Camera That Detects Walls

Hi all,

here’s my scene -

I’m trying to get it so that the camera either detects the wall or is clamped to 180 degrees movement.

I’ve tried to create a new orbitCamera script to test, but any other script I make for the camera doesn’t receive any input even though it compiles without error.

So I’m currently using the basic Orbit Camera script.

Any ideas on how I can get this done?


Hi @Arnie,

I think you can do it by setting a trigger to the camera entity, and catch the triggerenter/triggerleave events.

Though if you are only looking on how to restrict the camera movement and your objects are fixed in their positions you could get away with setting a min/max yaw.

OrbitCamera.prototype._clampYawAngle = function (yaw) {
    return pc.math.clamp(yaw, -this.yawAngleMax, -this.yawAngleMin);   

Hi, thanks for getting back to my post so soon!

I’ve added as attributes:

OrbitCamera.attributes.add('yawAngleMin', {type: 'number', default: -70, title: 'Yaw Angle Min'});
OrbitCamera.attributes.add('yawAngleMax', {type: 'number', default: 70, title: 'Yaw Angle Max'});

and added into the functions like you said

OrbitCamera.prototype._clampYawAngle = function (yaw) {
    return pc.math.clamp(yaw, -this.yawAngleMax, -this.yawAngleMin);   

but still nothing, do I need to add something to the update function?


Yes, that was just example code, you will have to use that method in the same manner the _clampPitchAngle() method is being used:

Object.defineProperty(AnimatedOrbitCamera.prototype, "pitch", {
    get: function() {
        return this._targetPitch;

    set: function(value) {
        this._targetPitch = this._clampPitchAngle(value);

ah thanks man got it worked, top bloke :slight_smile:


1 Like