camera.attachControl(canvas) does not adust camera.cameraDirection?

I’m using camera.attachControl(canvas) to use the mouse to look around. But when I move the mouse, this doesn’t seem to change camera.cameraDirection.
But camera.position DOES change, when using the keyboard WASD keys.

Is there a way to get the direction after using the mouse? I’m trying to use this to get the most optimal view for my fixed-camera game.

UPDATE

camera.cameraDirection appears not te be meant to get the direction.
I use camera.getDirection(Vector3.Forward()) now , which seems to do the job.

3 Likes

Spot on :slight_smile:

Is there a reason why cameraDirection is not a getter? I find getDirection with the localAxis parameter a bit confusing.

I agree but we need to cover both case (local / global)

I’m sorry, I still don’t understand how to set a FreeCamera to look at a certain direction programmatically.

const camera_position = new BABYLON.Vector3(0, 20, -10);
const camera_direction = new BABYLON.Vector3(0, -0.7, 0.75);

  camera = new BABYLON.FreeCamera(
    'camera',
    camera_position.clone(),
    scene,
  );

  camera.cameraDirection = camera_direction.clone();

This doesn’t work. Can you help me?

You can use camera.setTarget(new BABYLON.Vector3(0, -0.7, 0.75))
The camera looks according to a target

This doesn’t really do what I want. I have a mesh at (0,0,0) but want the camera position to have the mesh at the bottom, looking over it. Your code centers the mesh in the middle.

I’m having trouble understanding what you want to do.
And using rotation, it doesn’t give you the direction the camera is looking ?

I’m trying to use the mouse and keyboard with camera.attachControl(canvas) to find the right position for my camera.

The problem was that I thought I had to use camera direction, which is a concept I don’t really understand. But I found out that the camera.rotation property changes as well (just like camera.position) when using the mouse and keyboard to move and look around.

So I now use:

const camera_rotation = new BABYLON.Vector3(0.8, 0, 0);
camera.rotation = camera_rotation.clone();

I think it’s solved now :slight_smile:

2 Likes