0 votes

Hi there!

In my game, I need to rotate the player by 90 degrees or which I have working but it just snaps to 90 degrees, which works but doesn't look good, and I couldn't find any videos or anything in a syntactic so I was wondering how I would do that.

If you can help big thanks ahead of time!

in Engine by (101 points)

1 Answer

0 votes

You could add a small number to your rotation_degrees.
For example if you want the player to rotate from 0 to 90 degrees
you can say:

func _physics_process(delta):
    if rotation_degrees < 90:
        rotation_degrees += 0.5
by (19 points)

Hi, thanks for the reply!
does this mean there's only a "hacky" way of doing it, no method to do it in a nicer/efficient way of doing it? If there's not that's fine and thanks for the help!

You could make the smoothing (less "hacky", I suppose) by defining a rotation speed angularVelocity, and then apply the speed with the delta (e.g., rotation_degress += delta * angularVelocity, so even if your game lags the rotation will appear smooth.

If your game requires the player's sprite rotation to determine hitboxes (shooting) or what not, you could apply the solution proposed by BardlaAB87 to achieve visual smoothness, but keep track of a seperate variable (e.g. actualSpriteRotation), so mechanically the player would instantly snap 90 degrees (you would do actualSpriteRotation += 90), allowing for immediate accurate actions based on sprite rotation angle, but the sprite would be visually catching up by rotating the sprite towards the actualSpriteRotation angle

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.