Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Sakura37 |
I want to make a character stop moving when I use one of the attacks(even if i press the arrows, to still not move). How can I do that?(I am a begginer). I read something about yield, but i didn’t quite understood and i don’t know if i need to use it…so if there are another methodes…
This is my code:
func _physics_process(delta):
var current = state_machine.get_current_node()
var velocity = Vector2.ZERO
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
velocity=velocity.normalized()*SPEED
if velocity.length()==0:
state_machine.travel("idle")
if velocity.length()>0:
state_machine.travel("walking")
velocity=move_and_slide(velocity, FLOOR)
if Input.is_action_pressed("ui_power1"):
state_machine.travel("attack1")
return
if Input.is_action_pressed("ui_power2"):
state_machine.travel("attack2")
return
if Input.is_action_pressed("ui_power3"):
state_machine.travel("attack3")
return