Position vs new Vector3

Hi there, hope you are having a good Tuesday!

In my project I’ve been creating a character component, called playerCylinder, which has a camera parented to it.

In example A, i created the camera like this:
Screenshot 2022-08-23 at 15.01.22
What ended up happening, is that the camera moved faster than the cylinder, and after a while the camera and playerCylinder would be far apart.

I then created the camera like this instead, and it worked completely normally, with the camera and playerCylinder moving at the same rate!

So it got me thinking, what is the difference between these two implementations?

return(box.position == new Vector3(box.position.x, box.position.y, box.position.z)) //False

Sorry for the stupid question XD

position is a property of type vector3.

The constructor for the UniversalCamera expects a Vector3 as the second argument to set the camera position.

In your first code snippet you are not passing a Vector3.

2 Likes

You could use a shorthand as well - Vector3 | Babylon.js Documentation (babylonjs.com):

camera = new UniversalCamera(
  "UniversalCamera",
  playerCylinder.position.clone(), // same as new Vector3(playerCylinder.position.x, ...);
  scene
);
...
2 Likes

Ah, that was a typo when I was making the screenshot, apologies.

In my code I was passing in playerCylinder.position as the second argument but it had the same error as mentioned

Thank you both for the help, really appreciated!