21-12-2020, 02:53 PM
(This post was last modified: 21-12-2020, 02:55 PM by josemendez.)
Hi there,
Obi collision events just give you a list of all contacts during the current frame. If you store both this frame's contacts and the current frame's contacts, getting enter/exit/stay events is trivial:
- Contacts appearing in the current frame but not in the previous one are new, hence a enter event.
- Contacts appearing in the previous frame but not in the current have disappeared, hence a exit event.
- Contacts appearing in both frames continue to exist, hence a stay event.
Checking this can be done in linear time (O(n + m),where n and m are the amount of contacts in previous and current frame) using a zipper-like algorithm. This is exactly what the sample ObiContactEventDispatcher component does. You can find it at Obi/Scripts/Common/Utils/. This component will trigger an event for each enter/stay/exit, that you can subscribe to and perform any custom logic.
cheers,
Obi collision events just give you a list of all contacts during the current frame. If you store both this frame's contacts and the current frame's contacts, getting enter/exit/stay events is trivial:
- Contacts appearing in the current frame but not in the previous one are new, hence a enter event.
- Contacts appearing in the previous frame but not in the current have disappeared, hence a exit event.
- Contacts appearing in both frames continue to exist, hence a stay event.
Checking this can be done in linear time (O(n + m),where n and m are the amount of contacts in previous and current frame) using a zipper-like algorithm. This is exactly what the sample ObiContactEventDispatcher component does. You can find it at Obi/Scripts/Common/Utils/. This component will trigger an event for each enter/stay/exit, that you can subscribe to and perform any custom logic.
cheers,