Laggy camera

What’s wrong with this camera setup? I tested not having a transform parent (used for easy centering), tested bypassing message system. Shouldn’t the camera always center on the object? Instead you can see it goes a little ahead.

Self contained samples based on https://github.com/britzl/publicexamples/tree/master/examples/camera

camera-test-laggy.zip (27.0 KB)

camera-test-lag-module.zip (27.5 KB)

Here is a more extreme example with click and drag accelerated scrolling to show how bad it gets !? Simple fix and I’m just doing something stupid I hope?

camera-test-extreme.zip (27.8 KB)

And less extreme with click and drag but it should still center??

camera-test-less-extreme.zip (27.9 KB)

If you disable the camera you can see the object does move smoothly and isn’t jumping around like how it appears with the camera enabled.

1 Like

Ah, I see, yes, that sure looks weird, and I believe I’ve seen this in my own example as well. It’s caused by the use of a camera.script to send the view projection instead of a proper camera component. If you switch to a camera component and acquire camera focus the problem will go away. I did however find a solution that works when you use a script instead. If you do the view projection update after the update function instead of inside the update function of the camera.script you will get no jitter. Like this:

camera.script:

function update(self, dt)
	if self.enabled == 1 then
		msg.post("#", "update_camera")
	end
end

function on_message(self, message_id, message, sender)
	if message_id == hash("enable") then
		self.enabled = 1
	elseif message_id == hash("disable") then
		self.enabled = 0
	elseif message_id == hash("update_camera") then
		local aspect_ratio = (self.auto_aspect_ratio == 1) and default_aspect_ratio or self.aspect_ratio 
		local projection = vmath.matrix4_perspective(self.fov, aspect_ratio, self.near_z, self.far_z)
        ....
2 Likes