Hello all, I’m new in PlayCanvas and I’m making some small games to understand if the game engine can fit my needs.
I have a problem with the triggerenter event, this event seems to be raised on the trigger entity (the one with only the collision component) but not on the rigidbody entity (the one with both rigidbody (kinematic) and collision component). From the documentation (https://developer.playcanvas.com/en/api/pc.CollisionComponent.html) it seems that this event should be raised on both the trigger entity and rigidbody entity.
This is the test scene: https://playcanvas.com/editor/scene/848732
I have a BallProva script that register onTriggerEnter to triggerenter event. If I add BallProva to the trigger entity (LeftWallTest) it print correctly on the console (so the event is rised). If I add BallProva to the rigidbody entity (BallTest) there are no print to the console (so the event is not rised).
I think the issue here is that there is no entity that acts as a trigger.
When two entities collide the onTrigger events will fire only if one of the two is a trigger. For an entity to act as a trigger it should have only a Collision component and not a rigid body component. As then it would be part of the physics simulation.
If you haven’t already done, take a look at the following tutorial it explains a bit more on the subject:
Hello Leonidas, thank you very much for your answer.
I don’t know if you opened up the project, but there is exactly the entity trigger (the one with only a Collision component), and if I add the script to that entity the triggerenter event is rised. The problem is that this event is not rised on the entity with the rigidbody that trigger with the entity trigger
Right, I am not sure that is a bug or something expected and the docs are in error here (since they state that the event will fire in both entities, both the trigger volume and the rigidbody entering the volume).
There is an issue about that in the engine repo, you can submit your findings as well so someone can take a look at:
For the moment as a workaround, on the trigger volume when the events fire, you get the other entity as an argument returned:
Test project:
I have attached same script to Box and the plane, of trigger enter, only the plane is firing the event to the console ( open console to check) . https://playcanvas.com/editor/scene/975092
To be fair, this table was a bit confusing to me too. Perhaps an example could be added on how to read it. I mean, I can look at the bottom left and say, hey, so here is a trigger volume, follow to the right, and see that it shares the trigger events with rigidbody. Eurika. But it won’t work. Once you know that rigidbodies and triggers fire different events of the same name, then it makes sense, but may be confusing if you are not familiar.
Hello,
I wanted to know if it would be a problem if the trigger volume was moving?
In my code, I have the trigger volume change position based on its parent’s position.
This trigger volume only has a collision component and no rigidbody. but the “triggerenter” event never gets called.
Although if I give it a rigidbody and look for “collisionstart” event, the event gets fired.
But I want this entity to strictly be a trigger volume (based on the design of the game).
the warpsphere script has the code for onTriggerEnter (triggerenter event), but nothing is fired.
Holding Space button increases the size of the trigger volume (I confirmed this by debugging in the console)
‘A’ and ‘D’ key for left and right movement.
but the event does not get fired. its important to have the sphere set as trigger volume only as I don’t want it to push the entities it collides with.
Can’t this be changed? Something like that could keep me busy for a long time because I would also assume that disabeling of a component should suffice.