Here’s my code for updating the angle of my turret:
function update(self, dt)
if self.commanded_target ~= nil then
local target_angle = go_transform_angle(go_angle(self.commanded_target))
local current_angle = go.get_rotation().z
local angle_diff = angle_difference_2d(target_angle, current_angle)
local dt_angle = angle_diff * 0.5 -- *dt
go.set_rotation(vmath.quat_rotation_z(current_angle + dt_angle))
print(current_angle, angle_diff, dt_angle, dt_angle * 0.1)
end
end
I have validated angle_difference_2d
etc.
If I set dt_angle = angle_diff
, then everything works perfectly.
Instead, I wanted an easing effect, so I used dt_angle = angle_diff * 0.5
.
(Eventually, I want to apply limits on the rotation speed, but let’s not complicate the issue)
I expected angle_diff to halve each tick, causing the turret to approach its target.
But what happens in reality is that current_angle
is never updated as I would have expected by go.set_rotation
and so the turret always gets stuck pointing exactly halfway between its initial orientation and its target.
I’ve had a similar vein of issues all week trying to ease between angles using get_rotation
and set_rotation
. Any ideas?