Long story short, I’m working on a project where the user can move a sphere with the mouse over a plane. At certain areas on this plane, the user needs to be warned that that area is a bad location to place the item they are moving. (There’s a video of this at the bottom of this post).
To achieve this I’ve tried using the ammo physics engine where I create a trigger volume on the areas that are “bad”, and I’ve added a collision component as a sphere with a Kinematic rigid body.
The issue I run into is that the trigger events are sometimes delayed. I’m unable to replicate exactly what is causing this. But I’m sometimes able to move the sphere outside of the bad area without the “ontriggerleave” event triggering instantly.
I’ve created a simple project replicating this:
https://playcanvas.com/editor/scene/1939606
Where I have a box as my triggervolume and a sphere that is constantly moving in and out of the trigger volume. As soon as the sphere enters the trigger volume I swap the material on the box.
As you can see in the project, the material update is sometimes instantaneous, and sometimes it’s delayed quite a bit.
I’ve also made sure that it’s not the actual material change that is slow, as I’m still able to see this error just by logging the “ontriggerleave” event when I manually move my object without doing any material updates.
Here’s a video from the test project showing that the material update is sometimes delayed and sometimes not:
Here’s a video from my actual project where you can see the actual usecase. The first couple of times it works fine, but in my last attempt, I’m able to move my “sphere” outside of the area and the triggerleave doesn’t happen until 2 seconds after I’m outside it.
So my question is:
Looking at how I’ve setup my physics bodies in the test project. Is it something I’ve misunderstood or implemented in a weird way?
Is there any adjustments I can make to fix this delay?
Or do I just have to live with this as these are limitations on the phyiscs enginge?
Worth noting is that I’ve tried using both types of events. Collision events from the sphere, and Trigger events from the box. Both have the same result. It’s usually the “oncollisionend/ontriggerleave” events that are delayed.
I guess an alternative would be for me to write these methods myself as I don’t really need most of the physics, such as gravity and friction etc. etc.
I literally only need to calculate wether or not two primitive objects occupy the same area. But it would be nice to be able to utilize Ammo in case the requirements change in the future.