Godot Version
4.2.2
Question
Been trying to rotate a sprite while the player is moving, 45 degrees one way and the other. Best I can do is get the sprite to spin at the speed of sound. Can at least reset the $Sprite.rotation when the player stops moving regardless of what is going on with the rotation.
I’d post code but I’ve tried so many ways to rotate the sprite that I’m sure I’m just missing a really basic way to .rotate, or otherwise get a ‘wobble’ effect for the sprite. Sorry if it’s a simple answer.
Because my account is new I have to link a youtube vid, but basically just the way the elephant wobbles while walking up to the door at the very start is the effect I’m going for.
Are you using an AnimationPlayer?
1 Like
What values were you using for rotation? I’m asking because rotation is in radians, so 45° would be PI / 4.0.
If you want to use degrees, you can just use rotation_degrees instead.
1 Like
Just drive the rotation with a periodic trigonometric function:
@export var frequency := 1.0
@export var amplitude := PI * 0.25
func _process(dt):
rotation = sin(Time.get_ticks_msec() * frequency) * amplitude
2 Likes
I have not been using an AnimationPlayer. Also, when trying hyvernox’s suggested solution: I ran into the same error I had been having (which I realize I should have mentioned) where the sprite would only tilt while moving, but not be wobbling. Still: I had not expected this many replies, and appreciate the help. As a beginner, it was still good practice, and was worth trying.
normalized reply was the solution. I definitely used sin wrong in one of my attempts, as implementing their code worked seamlessly. The trigonometric function they provided gets a sprite to wobble.
Thank you all for the replies, and for the solution on how to get the desired wobbling effect for a sprite.
1 Like
The key is to supply the real time as an argument to that sin function.
1 Like