[SOLVED] Changing camera priority on collision

So I am trying to figure out how I can either disable or switch the camera whenever it touches an entity, although I don’t know where to put the code or how to code the last line
the last line of camera priority doesn’t work so can I get help on this.

var Teleport = pc.createScript('teleport');

// initialize code called once per entity
Teleport.prototype.initialize = function () {
    this.entity.collision.on('triggerenter', this.onTriggerEnter, this);

    this.teleportPoint = this.app.root.findByName('TeleportPoint');
};

Teleport.prototype.onTriggerEnter = function (entity) {
    if (entity.name === 'Player') {
        entity.rigidbody.teleport(this.teleportPoint.getPosition(0,-1,0));
    camera.priority = 0;
    }
};

In your line of code, camera is a component of an entity, so you need to start with the entity that has the component to be able to access the component. (Like this.entity.camera or define another enity). Also be aware the example code was for a trigger entity and will not work if the entity with the script has a rigidbody component.

Okay, because the teleport code works, and it’s able to teleport just I’m having issues with the camera. But if what you say is true, where should I put the code to change the camera priority?

Alright, the place of the code looks correct to me, so you just need to define the entity that has the camera component on it. Assume it’s not the player entity directly, you can use findByName() or an attribute.

var Teleport = pc.createScript('teleport');

// initialize code called once per entity
Teleport.prototype.initialize = function () {
    this.entity.collision.on('triggerenter', this.onTriggerEnter, this);

    this.teleportPoint = this.app.root.findByName('TeleportPoint');
};

Teleport.prototype.onTriggerEnter = function (entity) {
    if (entity.name === 'Player') {
        entity.rigidbody.teleport(this.teleportPoint.getPosition(0,-1,0));
        findByName(JumpscareCam)
        camera.priority = 1
    }
};

okay so I have now done it but it is saying it’s not defined, I think I put it in the wrong place?

If the camera entity has the name JumpscareCam you can use the code below.

this.app.root.findByName('JumpscareCam').camera.priority = 1;

Okay thank you so much! It works now. :smile:

1 Like