Heya! I’,m currently trying to make a ceiling-mounted turret that points at the player’s head. I have adapted a tutorial I found for 2d to achieve this.
However, this results in smooth motion that slows down as the target is reached due to how my implementation of interpolation works. I want the node to rotate at a constant speed, stopping near-instantly (or instantly if that’s easier :P) when it reaches its goal.
I wish to achieve something like the effect shown at 4:24 in the tutorial. If anyone knows how to go about this, please let me know! Any and all help would be much appreciated.
Heya, thanks for the advice! I’ve never used atan2 before though, and I’m struggling to figure out how to use it for the two axis I need so that the turret points at the player both left to right and up and down.
atan 2 takes the difference between 2 points, and calculates a direction in radians
var dx = x2 - x1
var dy = y2 - y1
var angle = atan2(dy, dx)
lerping the turrents rotation is slightly cheaper performance in 2D, because look_at handles the turrets matrice which is more computation than necessary