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/