Move the camera to an entity

Hi the idea it’s to move my camera to a certain point using something like this if you can see you click in the in that blue thingy and it moves the camera I checked the click and point movement tutorial but I don’t get it how it moves the player.

Thanks for attention.

This is the link to my project

Hi @Julio_A.P,

Point and click should work quite fine in your case if you don’t have any obstacles in between.

It works by constantly checking if the player entity has reach its destination, that happens in the point-and-click.js script update method. To set the destination you use the movePlayerTo(worldPosition) method.


Hi Leonidas.
Thanks a lot the response. Yeah I was able to move the camera but for some reason the it moves beyond I would like so I must set a bound that it cannot trespass the position of the of the clicked entity. Thanks a lot again.

So one approach to that would be to add a pc.BoundingBox to cover your allowed area. Each time the player requests to move to a point check if that point is included in the bounding box, otherwise stop and don’t move the player.

// --- create the bounding box
const center = new pc.Vec3(0, 0, 0);
const halfExtents = new pc.Vec3(10, 5, 10);

const aabb = new pc.BoundingBox(center, halfExtents);

// --- in your movement code
if( aabb.containsPoint(selectedWorldPoint) === true){
   // --- point is valid, move

Thanks it worked. I already had a bounding box, changed the values to this this.groundShape = new pc.BoundingBox(new pc.Vec3(0, 0, 0), new pc.Vec3(10, 1, 10)); and it worked

1 Like