Is it possible to `camera.lockedTarget` on the mouse pointer when I use the `Following Camera`?

Hello Everyone

I have some cubes and I want to move the camera like flying through the cubes and following the mouse pointer. I want to know is it possible locked the camera (camera.lockedTarget) to follow the mouse pointer ?

here is my PG: https://playground.babylonjs.com/#DWPQ9R#441

I use following code but I didn’t any result.

        scene.onPointerDown = function (evt, result) {
        var pickResult = scene.pick(evt.offsetX, evt.offsetY);
        console.log(pickResult)
        camera.lockedTarget = pickResult.ray.direction;
    }

@Evgeni_Popov could you have a look at this one ? If not I ll do ASAP

1 Like

The follow camera only supports (abstract) meshes as locked target, not Vector3.

You will either have to construct a mesh to set as lockedTarget or use another type of camera.

2 Likes

Thank you so much for answering to my question. can I use the Universal Camera to do it?
or is it possible to construct a small mesh when I click the mouse pointer? I mean when I clicked the mouse where there is no mesh

Both is possible, you can try both methods.

You can create an abstract mesh just by doing new BABYLON.AbstrachMesh("name", scene); new BABYLON.AbstractMesh("name", scene);. Then you can set its position.

1 Like

Thank you so much :pray: :pray: :pray: :pray:

sorry for my question , I use the following code to build small mesh and then set it as a lockedTarget:

    scene.onPointerDown = function (evt) {
    var pickResult = scene.pick(evt.offsetX, evt.offsetY);
    var impact = new BABYLON.AbstrachMesh("impact", scene)
    impact.material = new BABYLON.StandardMaterial("impactMat", scene);
    impact.material.diffuseColor = new BABYLON.Color3.Red();
    impact.position = pickResult.ray.direction
    camera.lockedTarget = impact
}

https://playground.babylonjs.com/#DWPQ9R#443

but I have an error which said : BABYLON.AbstrachMesh is not a constructor

I spelled it wrongly, it is AbstractMesh, not AbstrachMesh.

2 Likes

Thanks a lot