Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | rredesigns | |
Old Version | Published before Godot 3 was released. |
Hello.
I have a weird problem. I’m using the following code to move a character in the 3d engine, and changing the animation too.
Only the spacebar actually works. For some reason, the other keys won’t change the value of “anim”, and therefore the animation player won’t change either.
Please ignore the repeated “Walk” assignments, they are just there as I was trying with all keys.
Previously, “anim” and “anim_next” were declared as empty strings. I’m using Godot 2.0 stable.
Thanks in advance.
if anim != anim_next:
print(anim)
anim_next = anim
anim_player.play(anim)
if Input.is_action_pressed("forward"):
anim = "Walk"
set_linear_velocity(Vector3(speed, get_linear_velocity().y, get_linear_velocity().z))
if Input.is_action_pressed("backwards"):
set_linear_velocity(Vector3(-speed, get_linear_velocity().y, get_linear_velocity().z))
anim = "Walk"
if Input.is_action_pressed("left"):
set_linear_velocity(Vector3(get_linear_velocity().x, get_linear_velocity().y, -speed))
anim = "Walk"
if Input.is_action_pressed("right"):
set_linear_velocity(Vector3(get_linear_velocity().x, get_linear_velocity().y, speed))
anim = "Walk"
if Input.is_action_pressed("btn_jump"):
set_linear_velocity(Vector3(get_linear_velocity().x, speed, get_linear_velocity().z))
anim = "Walk"
else:
anim = "Run"