–1 vote

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
in Engine by (92 points)

1 Answer

0 votes

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.

by (648 points)

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?

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

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

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.