Camera follow TransformNode

I want to set the position and direction of a camera to the position and direction of a transform node. Intended behaviour is that the camera will always be at the exact position and direction of the node when rendering:

init:
    this.camera = new Camera("Camera", new Vector3(0, 0, 0), this.scene);

loop:
    this.camera.position = node.position;
    //this.camera.direction = node.direction; 
    this.scene.render();

I tried it with the position so far, but the view doesn’t change. I read that the usage of Camera is discouraged, but I don’t need all the behaviour of the other cameras.

A playground would help us to help you.

Also a TransformNode does not have a direction property, it does have a getDirection method.
TransformNode - Babylon.js Documentation

1 Like

https://playground.babylonjs.com/#V7Q1C7

That’s basically the setup. One Camera, one TransformNode. Set camera position to node position. After that, render the scene. The canvas doesn’t show the camera at the expected position, but at the origin.

Well, appears that Camera doesn’t work. I resorted to UniversalCamera and using the following code:

node.getWorldMatrix().decompose(
    undefined, 
    this.camera.rotationQuaternion, 
    this.camera.position);
1 Like