Hello guys, i'm prototyping stuff, i was trying to make a turret object rotate smoothly with the player's camera and i did it, the problem is, when you rotate the camera fast, the turret goes faster and slowly gets slower until eventually it meets its destination, but gameplay wise i don't think that would be a good idea, having to wait until it gets where it needs to. So anyway here's the code i have:
var current_deg = deg2rad(rotation_degrees.y)
var spatial_deg = deg2rad(cam.rotation_degrees.y - get_parent().rotation_degrees.y)
var new_rot = current_deg
new_rot = lerp_angle(current_deg, spatial_deg, turret_speed * delta)
rotation_degrees.y = rad2deg(new_rot)
i also have a much simpler line of code too that does the exacly same job (at least i think it does...)
rotation.y = lerp_angle(rotation.y, cam.rotation.y - get_parent().rotation.y, turret_speed * delta)
To explain what i'm doing: i'm getting the rotation of the Y axis of the "camera" Spatial Node, subtracting it's parent node Y axis rotation (this makes so the turret acts like it is a part of something and not floating along with it) and then linear interpolating the rotation of the Y axis of the turret to meet the rotation of the camera.
I really don't know if there is better ways of doing this, i spent a whole day searching for better ways of coding this, but i'm begining to think that maybe i wasn't made for programing.
All that i want to know is if there is a way to make the speed of this rotation consistent, and if not, if there's a diferrent way of achiving something alike it.
Any help will be greatly appreciated.