[SOLVED] Triggerenter doesnt work

Hey guys i have set up an object with collider component in it, made object invisible so only collider is there. wrote a triggerenter code… but when i enter a collider nothing happens, there should be console output but there is none. for debugging i tried set collisionstart function - added rigidbody and it worked. but cant get my triggerenter working, im attaching photos.

I wanna mention that im moving my player object with translateLocal, but for debugging i also tried to use physics (applyImpulse).

Triggerenter also does not work for me, i followed the tutorial in the docs section,but when i tried to use it to make vents for my playcanvas among us(just teleporting) it did not work while on the other hand the rigidbody part of the tutorial worked

pretty close, ideally you would need the callback to be a separate function and you didnt specify the scope.
the result entity of the trigger is stored as other, so try using this :

SwitchTophysics.prototype.initialize = function() {
this.entity.collision.on('triggerenter',this.onCollisionStart, this);
SwitchTophysics.prototype.onCollisionStart = function(other) {
if(other.tags.has('player')) {
console.log('Trigger entered');

Also note that trigger events only fire on the trigger, not the rigidbody that interacts with it.

1 Like

It still doesnt work though, there is no output in error log neither in console log

Could you Share the Project link?

red is plyer trigger and green is target trigger

here is the scene : https://playcanvas.com/editor/scene/1025730

your Trigger has a rigidbody which it should’nt, in order for the triggerenter event to work.

Also looks like the player physics is not with the player itself looking at the debug physics render in game:

but it had disabled rigidbody, no change even when i removed it

Looks like I made a mistake, the Player tag’s are’nt the same, sorry

Yes i changed now, though still not it

here you have used translateLocal when it should be applyForce and it seems that for me atleast the enemy entity is one which is moving which has the Enemy tag instead of the Player entity


thats why script is called switch to physics, because in some part of game im using physics and in some i dont and this trigger is supposed to change it as i want

nah i ve added also

if(other.tags.has('Enemy')) {
console.log('Trigger entered');

but nothing happens

Hi @smokys,

Change the Rigidbody of the ‘Enemy’ (=red player) from dynamic to kinematic :slight_smile:

Found this gamedev stackexchange answer really enlightening.



That was finally it! Thank you so much <3

1 Like