How do I detect whether you're walking from a standstill (no speed)?

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

So I have this skidding system in my platformer project. It works, but it does it from a standstill, so it looks like the player is walking backward for a split second. as well. How can I prevent skidding from happening from a standstill?
Here’s the code in question:

if Input.is_action_pressed("Right"):
			if velocity.x < 200 and velocity.x > 0:
				$Sprite.play("Skidding")
				sideFlipActivate = true
				$Sprite.flip_h = true
			else:
				sideFlipActivate = false
			velocity.x = lerp(velocity.x, speed, 0.1)
			$Sprite.play("Walking")
			if velocity.x > 200:
				$Sprite.flip_h = false
		elif Input.is_action_pressed("Left"):
			if velocity.x > -200:
				sideFlipActivate = true
				$Sprite.play("Skidding")
				$Sprite.flip_h = false
			else:
				sideFlipActivate = false
			velocity.x = lerp(velocity.x, -speed, 0.1)
			$Sprite.play("Walking")
			if velocity.x < -230:
				$Sprite.flip_h = true
		else:
			$Sprite.play("Idle")
			velocity.x = lerp(velocity.x,0,0.3)

I forgot to mention, this is the part of code that actually controls skidding, I probably shouldn’t have dumped a huge chunk of it

if velocity.x > -200:
            sideFlipActivate = true
            $Sprite.play("Skidding")
            $Sprite.flip_h = false
if velocity.x < 200:
            sideFlipActivate = true
            $Sprite.play("Skidding")
            $Sprite.flip_h = false

SomieStuff | 2022-02-17 03:45

what does “do skidding from standstill” exactly means?
do you mean it start playing “Skidding” even if no input from the player is given?

i think your code might have some issues on the if/elif/else, but to understand you need to copy past the entire code, without splitting it (i dont know where the if velocity.x>-200 is supposed to go), and please also use the correct indentation or we wont understand which if/elif/else are connected

Andrea | 2022-02-17 15:13

I mean when you start walking without any previous speed the turnaround animation plays, that’s what I want to prevent. The code works fine, but I want to prevent that. I guess another way to say it is "How do I prevent this from happening if no speed was exerted before I pressed the key

SomieStuff | 2022-02-17 18:53

:bust_in_silhouette: Reply From: CassanovaWong

Greater or less than your lerp step, so:

velocity.x > 0.3 do this or velocity.x < -0.3 do that, or abs(velocity.x) > 0.3 do this-that else otherwise, do the no speed thing