+1 vote

Maybe someone can help me.
I am developing 2D platformer and I want to add the "Climb" function to my hero. I have implemented this, but this is not quite what I need. I have nine animations in AnimationPlayer. In the seventh animation, the position of the hero changes. How to give a command from the code, if the seventh frame is playing, then change the position. Now the position is changing with a delay of 0.61 sec. This decision is temporary. Sometimes it doesn't work synchronously. It happens, but it happens very rarely. Here is an example of my code:

func Climb():

if sprite.flip_h == false:
    climb_up = Input.is_action_just_pressed("Right") 
    target = new_position_r.get_global_position()

if sprite.flip_h == true:
    climb_up = Input.is_action_just_pressed("Left")
    target = new_position_l.get_global_position()

if player_state == state.Hang and velocity.y > 0:
    if climb_up:
        is_climb = true
        yield(get_tree().create_timer(0.61), "timeout")
        position = target
if player_state == state.Climb:
    yield(get_tree().create_timer(0.96), "timeout")
    is_climb = false
in Engine by (47 points)
edited by

1 Answer

0 votes

Well, in the AnimationPlayer node you can add a method call at a particular frame. It works like a signal which calls a method. In that method you can have whether branching you like.

Also, have you considered using AnimationTree? That's a node that's there for precisely this sort of animation management.

There are several options, one is to use a BlendTree, so you can tie the animations together, you can blend them, you can add a TimeScale to forwards and backwards, a seek to jump to a particular point, etc. then you can add a script to this node and just call it.

Otherwise there's 2d and 3d blend spaces which will lerp between states. Or there's a state machine.

Much easier to use these nodes than code everything. It's very powerful.

by (2,087 points)

Thanks for your answer! You gave me some ideas for solving my problem.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.