Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Collision versus Trigger
#1
Hi.

I am experimenting with Obi Fluid in 2D, great fun! Trying to make fluid particles stream down a staircase of several static colliders. When they come down they should be teleported back up again. I have seen demos of using collision callback functions for this. I get callbacks for each frame for each particle colliding with every collider. To check for the proper collider in every callback must be a performance issue?

Can the Obi OnCollision event be active only for certain colliders? For example the ones that are triggers?

What is the best setup in a case like this?
Reply
#2
(28-06-2019, 11:04 AM)Belisica Wrote: Hi.

I am experimenting with Obi Fluid in 2D, great fun! Trying to make fluid particles stream down a staircase of several static colliders. When they come down they should be teleported back up again. I have seen demos of using collision callback functions for this. I get callbacks for each frame for each particle colliding with every collider. To check for the proper collider in every callback must be a performance issue?

Can the Obi OnCollision event be active only for certain colliders? For example the ones that are triggers?

What is the best setup in a case like this?

Hi there!

Contacts are generated from scratch every frame. So yes, every frame you get a list of <particle, collider> pairs that are close to or have already collided.

Most physics engines work this way internally: After the contact pairs have been generated, and contacts have been solved (which involves iterating multiple times per frame over all contact pairs, just to put things in perspective) they iterate over all pairs a final time and call a callback function for each pair. Only difference with Obi is that Obi lets you perform this last iteration yourself, so you don't lose or gain anything with respect to a per-collider callback approach. In fact, this is generally a bit cheaper since if you don't need a callback, you can just inline whatever operation you need to perform inside the loop.

So just iterate over your contacts list, for each one see if you need to do something with it. It's as cheap as it gets, and very cheap compared to what the engine is doing internally.
Reply