lo-th / Oimo.js

Lightweight 3d physics engine for javascript
http://lo-th.github.io/Oimo.js
MIT License
3.05k stars 301 forks source link

Triggers and Sensors? #63

Open gregmax17 opened 6 years ago

gregmax17 commented 6 years ago

Apologizes in advance for repeating myself, I'm just really looking forward to answer.

I'm continuing off of this issue here: https://github.com/lo-th/Oimo.js/issues/61

Thanks you for response. However, I fail to see how this answer my second part of my question: having the bodies behave like a trigger.

Is there a way, in that example, to have one of the spheres turn to the green material while passing through their box, respectively?

Imagine in a first person shooter the player walks through a doorway to go into a room full of monsters that spawn upon entering. In that door way as the player collided with a box trigger there was no actual collision but instead a callback/event for me to start spawning monsters. Make sense?

Is there a behavior like this available?

erosmarcon commented 6 years ago

Apparently I came up with a solution that seems to work at least for the time being. I added a flag 'isTrigger' to the RigidBody and modified World.js at line 530 adding another condition:

if(( b1.isDynamic && !b1.sleeping || b2.isDynamic && !b2.sleeping ) && (!b1.isTrigger && !b2.isTrigger) ) contact.updateManifold();

By doing so the body doesn't physically react to collisions, but still trigger contacts.

@lo-th Do you think it could affect your code elsewhere?