#Making rotation smooth and limited

1 messages · Page 1 of 1 (latest)

modest totem
#

I searched online but couldn’t find anything that worked. I have the player point towards mouse pointer, but I don’t want it to instantly point, I want it to smoothly rotate until that point not at instant speed.

fiery sleet
#

Get the local mouse position, then the angle towards that. From there you can get the sign of that angle, which is the direction you need to rotate. Then you can rotate with a rotation speed just like you would a movement speed.

#

(But with the extra check that if the total turn needed is less than you will turn this frame, just set your rotation, so you don't overshoot)

#

Here's a modified snippet of the code that I use;

var rotation_wanted = get_local_mouse_position().angle()
if abs(rotation_wanted) < turnSpeed * delta:
    rotation += rotation_wanted
    velocity = velocity.rotated(rotation_wanted * inertialStabilization)
else:
    rotation += sign(rotation_wanted) * turnSpeed * delta
    velocity = velocity.rotated(sign(rotation_wanted) * turnSpeed * delta * inertialStabilization)

turnSpeed is the turning speed in radians per second
inertialStabilization is the amount of momentum that turns with you, between 0 and 1 (inclusive).

modest totem
fiery sleet
#

Yeah that'll work fine so long as the max speed remains low. But if that's not something you need to worry about, then by all means, simplify, simplify, simplify, and all that.

#

So long as MaxSpeed/10 is always lower than the inverse of delta it won't cause any bugs. And an decelerative turns speed like that can certainly be a cool effect.

modest totem
#

Permanent bonuses to speed will only take it to 58, and temporary bonuses wont take it high enough to be a problem, as if you expected frame rate to be 60, (or 30 when its going slow) you would need 600 (or 300) speed for it to start breaking.

#

Nvm, twice that, but it still shouldn't be a problem

#

I changed the equation to this so now I definitely dont have to worry
rotate(get_angle_to(get_global_mouse_position()) * delta * 0.5 * pow(MaxSpeed, 0.5))