Camera Raycasting

Hello, I think I need to add “raycasting” to the camera for my ramp game, but I don’t know how. Exactly what I’m trying to do is, I don’t want the camera’s field of view to get into the track while I’m on these spherical tracks. Instead I want it to move down and return to the same position after 1 second. How can I put this into code?

Summary: I want the camera’s angle of view to change when an object enters a collision course

If you want to test the game: Ramp

CameraController:

var CameraController = pc.createScript('cameraController');

CameraController.attributes.add('Sphere',{
    type: 'entity'
    
});

CameraController.attributes.add('offset',{
   type: 'vec3' 
});

// initialize code called once per entity
CameraController.prototype.initialize = function() {
    if(this.Sphere){
        this.offset = this.entity.getPosition().sub(this.Sphere.getPosition());
    }
    
    
};

// update code called every frame
CameraController.prototype.update = function(dt) {
      if(this.Sphere){
          this.entity.setPosition(this.Sphere.getPosition().add(this.offset));
      }
};

// swap method called for script hot-reloading
// inherit your script state here
// CameraController.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/

Hi @Onur_Ozturk,

Trying to understand what you are asking here with raycasting.

To change the field of view you can do so like this:

this.entity.camera.fov = 75;

Are you having trouble checking when your player enters the cylindrical parts of your level?

Hello @Leonidas,
No, while the sphere is going very fast, as seen in the image below, the camera enters from the outside inwards and seems to pass through the track, while entering the cylinder or a covered track. In this case I want the camera angle to move downwards. When the sphere enters the cylinder, I want it to go back to its original angle.