AnimationTree

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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
:bust_in_silhouette: Reply From: andersmmg

If I understand you correctly, it sounds like you want the character movement to be paused while the attack animation plays. You probably want to use the functions in animation. Just trigger a function to pause controls at the beginning of animations and another at the end to continue. There are many ways to do this, but a very simple way would be to have a variable like movement_paused and set it based on those animation functions. Then, just check the variable in your movement code.

but how can i pause the controls? When the animation starts, i can modify the value of the variable, but how do i know when the animation it’s finished? Do i make a call method track or i can solve it easier?

Sakura37 | 2019-10-14 20:04

You can run script functions at any point in an animation, or you can use the signal for when the animation ends.

andersmmg | 2019-10-14 20:56

In case you’re wondering, to call the function, you use a Call Method track

andersmmg | 2019-10-14 21:06