#Making rotation smooth and limited
1 messages · Page 1 of 1 (latest)
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).
Thanks for the help, but I've ended up just using
rotate(get_angle_to(get_global_mouse_position()) * delta * MaxSpeed/10)
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.
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))