Bug within setTarget-function for z-up

Hi everyone,

this topic is already posted in the html5gamedev forum, it is not approved yet but i will add the link as soon as it is…

i am having a problem with the setTarget method when cameraUp is set to (0, 0, 1).

Can you checkout this pg?: Playground

depending on how often this block is called

    camera.setTarget(new BABYLON.Vector3(0, 7, 10));

the camera position changes and the objects in the scene are visible or not…
but it should not make a difference how often i call setTarget i guess

please checkout the results of the console log statements as well.

Those are:

e {x: -9.184850993605146e-16, y: 4.999999999999999, z: 3}
VM91:18 e {x: -1.1102849226888157e-15, y: -2.9000000000000004, z: 5}
VM91:21 e {x: -8.201425513350847e-16, y: -5.1000000000000005, z: -2.8999999999999995}
VM91:24 e {x: -5.510910596163087e-16, y: 2.9999999999999982, z: -5.1}
VM91:27 e {x: -9.184850993605148e-16, y: 4.999999999999999, z: 2.9999999999999973}

y and z values are getting switched and the sign switched too.

i expect the issue to be caused somewhere in here?:

Every comment on that is appreciated!

That’s the old forum, so don’t worry about it. You should use this forum. :slight_smile:

I can’t repro the behavior you see. On my machine using Chrome, I see the following in the output window:

Babylon.js v4.0.0-alpha.22 - WebGL2
VM72:15 eisNonUniform: (...)x: -9.184850993605148e-16y: 4.999999999999999z: 2.9999999999999973__proto__: Object
VM72:18 eisNonUniform: (...)x: -9.184850993605148e-16y: 4.999999999999999z: 2.9999999999999973__proto__: Object
VM72:21 eisNonUniform: (...)x: -9.184850993605148e-16y: 4.999999999999999z: 2.9999999999999973__proto__: Object
VM72:24 eisNonUniform: (...)x: -9.184850993605148e-16y: 4.999999999999999z: 2.9999999999999973__proto__: Object
VM72:27 eisNonUniform: (...)x: -9.184850993605148e-16y: 4.999999999999999z: 2.9999999999999973__proto__: Object

Is there something special about your set up?

Thanks for your reply @bghgary ! oh ya, i just realized: only if the console is open before i press ‘run’ the output values match the ones i added to the post. if i hit run first (or just open the page) i get the same result as you do. but in both cases - if i delete the last setTarget() block -

camera.setTarget(new BABYLON.Vector3(0, 7, 10));

the position of the camera changes and the objects are not visible anymore… :confused:

You can setTarget as much as you like.

Bug seems related to


or something deeper than that.
As a get function it shouldn’t change anything, but it clearly does.

uncomment any camera.getViewMatrix and it messes the camera up.

Upon some further investigation, it seems multiple functions are affected, including setTarget as you wrote.
Looks like the cache isn’t updated and old values being used perhaps?

1 Like

Yup. Looks like a bug.

Here is a min repro:

It is actually not a bug per se.

The getViewMatrix() call is also updating internal and external computed properties like position (as the position of an ArcRotateCamera is based on alpha, beta and radius).

For user convenience the camera.position is computed out of alpha, beta and radius as soon as the viewMatrix is built (it is easy and fast to extract that info from the matrix itself)

In the repro shared by @bghgary, the getViewMatrix call will update the position property which in turn is used by the setTarget call (as the setTarget call will compute alpha, beta and radius from position and target).

So if you call setTarget BEFORE getViewMatrix all is fine as camera postion was not yet moved.

Hopefully it makes sense

Hmm yeah that makes sense,
Any explaination for this behavior? ( line #20 )

Maybe it’s the same, I would just assume a setTarget would simply change the target property and update alpha/beta/radius to keep the same position or atleast the same angle & distance

yes this is the same issue.
Calling setTarget uses camera.position which is ONLY updated during camera.getViewMatrix call:


I know this is not ideal so I will update the setTarget function to first call a getViewMatrix to make sure the camera.position is updated first