Sign in to follow this  

free camera rotation?

Recommended Posts


I think I am not very well understood the function of the rotation properties on a free camera ...
Watch this playground:

Why does my variable rot changed?
I think I must be so tired to understand the problem :(

If someone has an explanation for this problem thank you.

Ps: It works very well with an arcRotatecamera by adjusting Alpha and Beta values.

Thanks ;)

Share this post

Link to post
Share on other sites

@Deltakosh There seems to be something wrong when assigning something to a Vector3 method like .position or .rotation, I've noticed this behavior before and I thought that I was doing something wrong, what I did is create two box meshes "Box1" and "Box2" and set :

box1.position = box2.position;

This somehow affected the box2.position.

And @Xav's example shows exactly whats wrong, but using a variable instead.


Is also acting like :

rot = camera.rotation; 


Share this post

Link to post
Share on other sites

Object assign in JavaScript won't create a copy but a reference.

When you say camera.rotation = rot; and later change rot, camera rotation will change as well. It is a reference to the same object. The only object types that are being copied and not referenced are the primitives (numbers, string, booleans). 

So, this is just the way JavaScript works. Want to prevent that? use the clone() function of the vector (box1.position = box2.position.clone()). this will create a standalone clone with the same details of the original vector3.

Just to explain what happens in the demo - 

after clicking you assign camera.rotation = rot. Then you change the camera rotation object, which is now the rot variable. so they both change (they are the same object). Then you click again, but rot is already camera.rotation. And nothing happens. camera.rotation.copyFrom(rot) will be the right way to go here.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.