How to make a static camera set to a given position and orientation?

I’m trying to make a scene with a static camera. The camera should not be moved with keyboard and mouse input and I want to set its position with a Vector3 and set its orientation with Quaternion. I’m currently looking at targetCamera Babylon.js/packages/dev/core/src/Cameras/targetCamera.ts at master · BabylonJS/Babylon.js · GitHub
This camera has both target and rotationQuaternion member variables but it looks like the target drives setting the rotationQuaternion vs being able to directly set it.
Any suggestions on if I’m going down the right path or should I drop all the way to base the base Camera?

Can you create a camera and not assign controls to it?

1 Like

Yes, here is a codepen where I have taken a standard sample and switched it to use a TargetCamera and did not attach controls. Setting the orientationQuaternion to any Quaternion has no effect.

A playground would be easier for forum users to help you.

What about something like this?

const rotationZero = new BABYLON.Vector3.Backward(); // camera direction with Identity() rotation
const rotationQ = BABYLON.Quaternion(1,0,1,1);
rotationZero.rotateByQuaternionAroundPointToRef(rotationQ,this._camera.position,this._camera.target);

Edit: you also could use the current target as the zero rotation:

this._camera.target.rotateByQuaternionAroundPointToRef(rotationQ,this._camera.position,this._camera.target);

Hello @Don_Gillett :slight_smile:

You are missing a new to call the constructor.
this._camera.rotationQuaternion = BABYLON.Quaternion(1,0,1,1);
:arrow_down:
this._camera.rotationQuaternion = new BABYLON.Quaternion(1,0,1,1);
See this Playground :slight_smile:

2 Likes

Another reason to switch to Typescript :slight_smile:

1 Like

Doh… thanks for finding this. My project is TS but I I actually use BabylonJS-react and do most things declaratively. I thought I was doing the right thing be providing an example in codepen which wasn’t catching my error. I will switch to playground with TS examples.
Thanks again!