#i'm give up trying to put an jump animayion

1 messages · Page 1 of 1 (latest)

shell oyster
#

It's been 1 hour and I can't get the "Jump" animation, I've already tried changing the code, I've seen at least 10 tutorials on YouTube, and nothing worked, I couldn't get the jump animation, and at this point I've given up on everything, there will no longer be a jump animation in the game I'm making, and I've already resigned myself to it, and there's nothing else I can do, it's over

if someone, some kind of demi god knows how to put the jump animation on this code, it would be the nicest thing someone has made for an dumb in programation like me

#

extends CharacterBody3D

@onready var animation_crash = $Crash/Woah/AnimationPlayer

const SPEED = 4.7
const JUMP_VELOCITY = 6.5

func _physics_process(delta):

# Add the gravity.
if not is_on_floor():
        
    velocity += get_gravity() * delta
    
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
    
    velocity.y = JUMP_VELOCITY

# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")

# new vector3 direction, taking into account the user arrow inputs and camera rotation
var direction = ($"camera controler".transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()

#rotate
if input_dir != Vector2(0,0):
    $Crash/Woah.rotation_degrees.y = $"camera controler".rotation_degrees.y - rad_to_deg(input_dir.angle()) + 90


if direction:
    if animation_crash.current_animation != "run":
        animation_crash.play("run")
        
    velocity.x = direction.x * SPEED
    velocity.z = direction.z * SPEED
else:
    if animation_crash.current_animation != "idle":
        animation_crash.play("idle")
        
    velocity.x = move_toward(velocity.x, 0, SPEED)
    velocity.z = move_toward(velocity.z, 0, SPEED)

move_and_slide()

#make camera controller match the position of myself
$"camera controler".position = lerp($"camera controler".position, position, 0.25)
#

I'm just putting this out there to test my luck, i don't see why anyone would want to help me ;-;

brisk cargo
#

I don’t see anywhere where you try to set the animation to jump in your code

#

Did you remove it?

shell oyster
brisk cargo
#

Ok, it should go in a spot in your code where you aren’t on the floor, but you also need to make sure that no other code overrides the animation. Personally, I handle all my animations separately from a method, for example:

func handle_animation():
    if (!is_on_floor()):
        #the player is in the air, so play the jump animation
    else:
        #the player is on the ground, so play the run animations 

Then I usually put the handle_animation() method at the end of my _physics_process()

#

This isn’t the only way to do it, but it keeps all my animation code in one spot instead of being spread all over the movement code

#

It’s also important to use the if else because we do not want the run or jump animations to play at the same time. Either we are in the air jumping or on the ground running. Does that make sense?

shell oyster
#

It's working!