# Laggy camera

**URL:** <https://forum.defold.com/t/laggy-camera/7703>\
**Category:** Questions\
**Created:** [April 23, 2017, 4:56am UTC](https://forum.defold.com/t/laggy-camera/7703 "2017-04-23T04:56:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [April 23, 2017, 4:56am UTC](https://forum.defold.com/t/laggy-camera/7703/1 "2017-04-23T04:56:25Z")

</div>

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 [publicexamples/examples/camera at master · britzl/publicexamples · GitHub](https://github.com/britzl/publicexamples/tree/master/examples/camera)

[camera-test-laggy.zip](https://forum.defold.com/uploads/default/original/2X/1/1e66d91ed3b1e699a77c24178c71773b75e164ff.zip) (27.0 KB)

[camera-test-lag-module.zip](https://forum.defold.com/uploads/default/original/2X/3/3b1c0791bf426f9e8f00c268c63c534086eaa9ac.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](https://forum.defold.com/uploads/default/original/2X/3/3cd73b4350f74bad5a034aaff955017693647d66.zip) (27.8 KB)

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

[camera-test-less-extreme.zip](https://forum.defold.com/uploads/default/original/2X/4/4d234b3d9440948805db5f22548255784f0b16d3.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.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [April 26, 2017, 8:08am UTC](https://forum.defold.com/t/laggy-camera/7703/2 "2017-04-26T08:08:40Z")

</div>

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)
        ....

```
