I’m making a 3D platformer, and I want a camera the follows the player. I can already do this by making the camera a child of the player, but now I want to make the camera orbit the player so I need some custom follow code (I have also tried RenderCam’s follow function, but it seems to ignore the Z axis).
The problem I’m having right now is that the camera always seems to be one frame behind the player, instead of following the player exactly.
Here’s the current follow code on the camera:
function on_message(self, message_id, message, sender)
if message_id == hash("update_pos") then
local focus_pos = go.get_position(PLAYER_ID)
local new_pos = focus_pos + vmath.normalize(self.direction) * self.distance
go.set_position(new_pos)
end
end
That “update_pos” message is sent just after the player sets its new position in update.
go.set_position(pos + newpos * dt)
msg.post("/camera#orbitcamera", "update_pos")
This seems to happen regardless of whether I update the camera position after the player, or vice versa. What’s the solution here?