# [SOLVED] Limit camera movements

Hi! I’m trying limit the camera movement in Y axes, my code:

MouseInput.prototype.pan = function(screenPoint) {
var fromWorldPoint = MouseInput.fromWorldPoint;
var toWorldPoint = MouseInput.toWorldPoint;
var worldDiff = MouseInput.worldDiff;
var lastPos = new pc.Vec3();
// For panning to work at any zoom level, we use screen point to world projection
// to work out how far we need to pan the pivotEntity in world space
var camera = this.entity.camera;
var distance = this.orbitCamera.distance;

``````var yPos = this.entity.getPosition().y;
var lastYpos = pc.math.clamp(y,0.6,3);
if(lastYpos > 0.6){
this.lastPos = this.entity.getPosition();
camera.screenToWorld(screenPoint.x, screenPoint.y, distance, fromWorldPoint);
camera.screenToWorld(this.lastPoint.x, this.lastPoint.y, distance, toWorldPoint);

worldDiff.sub2(toWorldPoint, fromWorldPoint);
}else{
console.log("1 "+this.lastPos +" "+ this.entity.getPosition());
this.entity.translate(this.lastPos.x, this.lastPos.y + 0.5, this.lastPos.z);
console.log("2 "+this.lastPos +" "+ this.entity.getPosition());
}
``````

The problem is, when i’m doing pan the Y is lower than the condition and never enter, i’m tried to set a position and don’t work, any idea?

Sorry for my english

If you are doing the clamp before this if statement, it will never enter the statement because it is always going to be 0.6 or lower.

Is the Y clamp relative to anything or do you know exactly where in world space you want to clamp it between?

1 Like

Sorry, this is the code

var lastYpos = pc.math.clamp(yPos,0.6,3);
if(lastYpos > 0.6){

My camara starts the scene in 0,1,0 (world space) and my idea is limit the Y until 0.6