How to move camera left & right no matter what direction it's facing?

Hi,

How would I get the cameras left and right vector?

 var direction = camera.getFrontPosition();

How would I rotate that vector3 by -90 or +90 deg?

I have a value already calculated xVel which is a range from -2 to +2 I need to move the camera left | right using on that value.

What would be the best way to do this? I can’t use FreeCamera’s built in movement keys for this.

Any ideas?

Thanks

D

Hi @Darcey

You can use this method :
https://doc.babylonjs.com/api/classes/babylon.camera#getdirection
The parameter vector corresponds to the local axis of the camera.
That means that

var cameraRight = camera.getDirection(new BABYLON.Vector3(1, 0, 0));
var cameraUp = camera.getDirection(new BABYLON.Vector3(0, 1, 0));
var cameraDirection = camera.getDirection(new BABYLON.Vector3(0, 0, 1));

Then you can modulate and add the vector to the camera position.

2 Likes

Looks like I somehow overlooked that method of the camera!

Nice 1.

Thanks

1 Like