How to implement VR and TOUCH?

Try the following: (note that it doesn’t restrict the user from fully rotating vertically to the point where they are upside down)

LookCamera.prototype.update = function (dt) {
    // Update the camera's orientation
    
    this.ex = pc.math.lerp(this.ex, this.targetEx, 1);
    this.ey = pc.math.lerp(this.ey, this.targetEy, 1);
        
    var q2 = new pc.Quat();

    if (this.magicWindowEnabled) {
        this.magicWindowOffsetEntity.setLocalEulerAngles(0, this.ey, 0);
        var rotation = this.magicWindowOffsetEntity.getRotation();

        q2.setFromAxisAngle(this.entity.right, this.ex);
        q2.mul(rotation);
        
        this.magicWindowOffsetEntity.setRotation(q2);
    }
    else {
        this.entity.setLocalEulerAngles(this.ex, this.ey, 0);
    }
};
1 Like