0 votes

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)
Godot version 3.4
in Engine by (14 points)
edited by

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

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

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

1 Answer

0 votes

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

by (215 points)
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.