how to detect when the player has stopped

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

im making a geometry dash game and i want the player to die when i run into a block and stop. i have a set velocity for gravity and for moving left.

func _physics_process(delta):
velocity.x = 255 #moves player forward
velocity.y += GRAVITY
if velocity.x == 0:
die()

but when i printed out my velocity it showed 255 and when i got stopped by the block it kept saying 255 even though i wasnt moving. is there some kind of function or way that can detect if my character stops moving?

:bust_in_silhouette: Reply From: Inces

velocity is not a built-in, it is a variable You made, and You are using it for movement in another lines of code. How do You expect it to become 0, when You set it as 255 every frame in process ? :wink:
Show the code of your actual movement. Are You using move_and_slide ? I bet You do. move and slide actually returns a value of real velocity, so You can do :

if move_and_slide(velocity,so on,so on).x == 0 :
        die()

Important thing is - You must use move_and_slide only once in a single script. The line above does two things - it moves the player AND kills it when its speed is dropped