Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Grizly |
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