#Rotation degrees bug when rotating player

9 messages · Page 1 of 1 (latest)

silk wolf
#

Hi!

As you can see in the video, when the cursor is in the zone of 90 degrees, the ship strangely rotates instantly, doing some kind of 360 flip, instead of rotating normally like it does in other areas of the screen.

This is my code:

var current_rotation : float = rotation

var target_rotation: float = get_global_mouse_position().angle_to_point(position)

rotation = lerp(current_rotation, target_rotation, smoothstep(0.0, 1.0, rotation_speed))

And this is my Sprite2D setup.

woven haven
silk wolf
#

Yes, @woven haven . But I want to be able to control the speed of the rotation and add a little smoothness to it.

That's why I went with the "hard" implementation

woven haven
#

Ok so I’m guessing your issue is because if the current rotation is 10 degrees and your target rotation is 350 it spins it all the way round instead of just turning the 20 degrees.

silk wolf
#

I honestly don't understand in the first place what could be the cause of the problem. But your guessing seems like a good start to identify the problem🤔

woven haven
#

Add print in your code to show the 2 rotation variables it will confirm what is happening.

silk wolf
#

Yes, you are right. I will test this tomorrow.

hard current
#

Easier with transforms, which come with a handy looking_at() function.

func _process(_delta):
    var target_rotation = global_transform.looking_at(get_global_mouse_position())
    global_transform = global_transform.interpolate_with(target_rotation, rotation_speed)
#

@silk wolf