How do I stop character movement?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dragonwarrior2004

My current project is an Action Adventure RPG with doorways that teleport you to new areas and uses a fade-in fade-out animation, however, the animation has to be connected to my player where the walking animations are. The only way to play the fade animations is to stop the players ability to move. How can I stop the functions that allow the player to move?

Maybe you could make velocity.x or velocity.y or both equal 0 if a variable is true or not. like:

var door_anim = false
func _physics_process(delta):
	if door_anim == false:
		#movement code and other stuff here
	else:
		velocity.x = 0

ianzzap | 2020-06-23 04:28

1 Like
:bust_in_silhouette: Reply From: njamster

How can I stop the functions that allow the player to move?

That depends a great deal on how you move the player. In most cases it will likely be enough to use set_process() or set_physics_process(). If you only want to stop the movement, but still continue to run other parts of your _process-code, use a boolean variable to gate the execution of your movement code:

var can_move = false

func _process(delta):
    print("This happens every frame")
    if can_move:
        print("This will only happen when can_move is true")

Thanks m8. I’ll implement that later, that makes so much sense!

Dragonwarrior2004 | 2020-06-23 13:44

1 Like