#Turret needs to aim at mouse cursor while maintaining constant limited speed

1 messages · Page 1 of 1 (latest)

waxen laurel
#

I have tried 3 different methods and cannot think of any others, I will list the methods below and why they have not worked for me.

#

This is the most effective method I've found but it flips direction (and goes all the way around) when going from 360 to 0

if abs(difference) < SPEED * delta:
  rotation = rotation_angle
else:
  rotation += signf(difference) * SPEED * delta ```

lerp does not have a constant movement value, and just following the mouse does not have the delay or movement speed limit I am looking for.
Pls help :<
lavish jay
#

The dot product might help you determine whether to turn right or left.
https://docs.godotengine.org/en/stable/tutorials/math/vector_math.html#facing
In the example, they use it to determine in front or behind, but it works the same for left and right. Use the character's y basis vector instead of their x-vector.

wooden heath
#

Godot has a helper function, I think it's called angle_difference, which you should use instead of plain minus

waxen laurel
#

Heres the updated functional code for anyone in the future with a similar issue