Hi @Sasa_Olmedo,
Here is how I did it, it’s a lot of small additions so follow closely:
// added two new attributes
OrbitCamera.attributes.add('yawAngleMax', {type: 'number', default: 90, title: 'Yaw Angle Max (degrees)'});
OrbitCamera.attributes.add('yawAngleMin', {type: 'number', default: -90, title: 'Yaw Angle Min (degrees)'});
Added a new property getter/setter:
// Property to get and set the yaw of the camera around the pivot point (degrees)
Object.defineProperty(OrbitCamera.prototype, "yaw", {
get: function() {
return this._targetYaw;
},
set: function(value) {
this._targetYaw = this._clampYawAngle(value);
}
});
Added this in the initialize method:
this._yaw = this._calcYaw(cameraQuat);
this._targetYaw = this._yaw;
Include it in the update(dt) method:
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);
this._updatePosition();
And finally in the _updatePosition() method:
this.entity.setLocalEulerAngles(this._pitch, this._yaw, 0);
And the methods used:
OrbitCamera.prototype._calcYaw = function (quat) {
var transformedForward = new pc.Vec3();
quat.transformVector(pc.Vec3.FORWARD, transformedForward);
return Math.atan2(-transformedForward.x, -transformedForward.z) * pc.math.RAD_TO_DEG;
};
OrbitCamera.prototype._clampYawAngle = function (yaw) {
if( this.yawAngleMax === 0 && this.yawAngleMin === 0 ){
return yaw;
}else{
return pc.math.clamp(yaw, -this.yawAngleMax, -this.yawAngleMin);
}
};