im not sure how to use math.clamp but this is the way i did but doesnt work.

i want the camera’s position to be within x >= -55 and x <= 75

camPosition.x = pc.math.clamp(camPosition.x, -55, 75);

is there a way to make it better? or correct it?

thank you for feedbacks.

```
OrbitCamera.prototype.update = function(dt) {
var t = this.inertiaFactor === 0 ? 1 : Math.min(dt / this.inertiaFactor, 1);
this._distance = pc.math.lerp(this._distance, this._targetDistance, t);
this._yaw = pc.math.lerp(this._yaw, this._targetYaw, t);
this._pitch = pc.math.lerp(this._pitch, this._targetPitch, t);
var camPosition = this.entity.getPosition();
this._updatePosition();
};
OrbitCamera.prototype._updatePosition = function () {
// Work out the camera position based on the pivot point, pitch, yaw and distance
var position = this.entity.getPosition();
this.entity.setLocalPosition(0,0,0);
this.entity.setLocalEulerAngles(this._pitch, this._yaw, 0);
position.copy(this.entity.forward);
position.scale(-this._distance);
position.add(this.pivotPoint);
this.entity.setPosition(position);
position.x = pc.math.clamp(position.x, -55, 75);
};
```

this is where i put them, is the order wrong? because the camera’s position.x can still go past -55 or 75

From a quick look, it seems like the clamp is being done but the clamped value is it being set back to the entity.

Try changing this:

```
this.entity.setPosition(position);
position.x = pc.math.clamp(position.x, -55, 75);
}
```

to

```
position.x = pc.math.clamp(position.x, -55, 75);
this.entity.setPosition(position);
}
```

1 Like

oh gosh, that was an embarrassing mistake. that solved it! thank you so much! and for the quick responses!