If position = (x,y,z) {}

Im trying to make a point and clicker puzzle game based of the dont escape series. ive decided to just. rest with something really simple. so when i move right the camera pans right. im making a limit for how far the camera can pan right. as seen in the title. can you show me? a code example would be the best. :slight_smile:

When you need the position of an entity you can use entity.getPosition(). This returns a pc.Vec3 where you can get the xyz values from, see the API reference:

So typing out your post title:

var cameraPosition = camera.entity.getPosition();
var cameraMinX = -100;
var cameraMaxX = 100;
if(cameraPosition.x >= cameraMinX && cameraPosition.x <= cameraMaxX){
    ... allow move
}

However I think I would approach this using a clamp:

When you are setting the new position of the camera, run it through the pc.clamp function:

var targetPosition = new pc.Vec3(x,y,z);
var camX = pc.math.clamp(targetPosition.x, minX, maxX);
var cameraPosition = new pc.Vec3(camX, targetPosition.y, targetPosition.z); //you can also clamp Y and Z if needed of course.
camera.entity.setPosition(cameraPosition);
2 Likes