I want to make Trigger where should I look into.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

I want to make Trigger where should I look into.

Post by parapoohda »

I want to make trigger(collision detection then do something. I think it is call hit box.) like trap, skill eg. aura(skill support allies around user), projectile like fireball or skill that cast on ground like storm gust(Ragnarok online).

Should I look into TankDemo, ContactEventDemo or create list of trigger that use handle from both ConfigureContactManifold to identify it.

My superior(my brother) think create list like contactEventDemo is just touch and not in it can't use like skilll like firewall(ragnarok online)(this skill damage enemy that in it and if not unleaded it will push it back); :D

Updated
From Tank Demo I think You keep list of trigger in NarrowPhaseCallbacks(that inheritance from INarrowPhaseCallbacks) then call it in ConfigureContactManifold is this will good for performance?Or where i should keep list

Thank you. You are really dedicate to bepuphysics. I appreciate you help.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: I want to make Trigger where should I look into.

Post by Norbo »

There's a few different high level approaches to consider:

1) Rough query volumes. For simpler queries where you only care about overlapping bounding boxes or centerpoint distance, simply querying the broad phase using Simulation.BroadPhase.GetOverlaps is a good choice. By avoiding contact generation, it's quite a bit faster than more precise tests. You can apply your own filtering after the fact- once you have the set of collidables with overlapping bounding boxes, you could check their centerpoints for distance to the center, for example. Bounding box level intersection of rays can also be done using Simulation.BroadPhase.RayCast.

2) You can perform your own contact-level queries by using the CollisionBatcher on the results of a GetOverlaps call. It's a little complex to use- you have to collect all the relevant information, and the batcher is built to operate across many tests at once. It'll give you the same raw contact information that the narrow phase callbacks would give you, though.

3) Having a collidable in the simulation which generates pairs and reports pairs/contacts through the narrow phase callbacks. If a query is intended to be long lasting (many contiguous frames, like a trigger region), this can be a little faster than a query that does the same thing since it's batched alongside the rest of the simulation. If you only need overlaps, you can use the AllowContactGeneration callback and return false to stop contact generation. If you need contacts and don't want constraints, the ConfigureContactManifold callback would do the trick (again returning false to stop constraints).

The ContactEventsDemo shows one example of #3. Individual collidables are registered as eventful in a dictionary. Determining whether a given collision should emit an event requires a dictionary lookup. The rest of the demo is just showing basic infrastructure about how to record the event and avoid re-emitting events every frame. This isn't the fastest or simplest approach, but it shows how an 'initial contact' event system could be made.

The TankDemo is another example of #3, but it uses a different approach that's a little more direct. Rather than having a dictionary of eventful collidables, TankCallbacks stores metadata about every single dynamic body by handle (the Properties field). In the callback, the collidable handle is used to look up that metadata. It uses a direct O(1) lookup. Based on that metadata it adds the event to the ProjectileImpacts list. Given the relative rarity of projectile impacts, a lock is used to append new events to the list. If your events are rare, this is fine. For extremely frequent events (hundreds of times per frame), you might have to adopt a strategy like per-thread event lists (like the ContactEventsDemo) instead to avoid synchronization overhead.
My superior(my brother) think create list like contactEventDemo is just touch and not in it can't use like skilll like firewall(ragnarok online)(this skill damage enemy that in it and if not unleaded it will push it back);
While the 'initial contact' event wouldn't be a great choice for something like a persistent firewall, contacts are still reported during deep collision, so a different version that reports every frame of collision would work. It's worth noting that meshes don't have volume, so you'd want to use primitives like Boxes or ConvexHulls instead to define a trigger volume. (Or track entry and exit events, but that would be complicated.)
Thank you. You are really dedicate to bepuphysics. I appreciate you help.
💖
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

Re: I want to make Trigger where should I look into.

Post by parapoohda »

1 Is it will be too overburden server to use ConfigureContactManifold every frame?
2 If it is overburden I want to know where to call function when it out or in.
Thank you.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: I want to make Trigger where should I look into.

Post by Norbo »

1 Is it will be too overburden server to use ConfigureContactManifold every frame?
The ConfigureContactManifold function is called by the collision detection pipeline for every single contact manifold found during a frame. Definitely avoid doing heavy lifting in there if at all possible. Doing simple stuff like just appending to a thread-local list is fine; doing console IO or something is definitely a bad idea.
2 If it is overburden I want to know where to call function when it out or in.
Sorry, not sure what you mean.
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

Re: I want to make Trigger where should I look into.

Post by parapoohda »

Thank you.
I will clarify my unclear question.
That time I think to make list of object that are contact or in that trigger.
Then I try to add when new object contact or in trigger.
And remove when it is out of trigger.
So I think I need to know which function being call when object is out of trigger.

But now I call function of object in SortedDictionary by handle in ConfigureContactManifold.
WRZ1
Posts: 8
Joined: Sun Sep 29, 2019 9:16 pm

Re: I want to make Trigger where should I look into.

Post by WRZ1 »

Like with the events there is nothing built into Bepu, I think you have roll your own.

One way to implement it: Keep track of the triggers you are currently overlapping with, and in the next tick compare that list with the currently overlapping objects. Now, if one of your tracked triggers is no longer overlapping you can consider this as you OnTriggerEnd.

edit: Just realized you've actually asked the same thing I tried to explain, haha. To add something useful then:

ConfigureContactManifold() should be a good place to do the trigger stuff. For example the character controller demo calls a method TryReportContacts() from ConfigureContactManifold(). There's then some decision-making going on, like is this a dynamic collidable, and is this a character.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: I want to make Trigger where should I look into.

Post by Norbo »

So I think I need to know which function being call when object is out of trigger.
Like with the events there is nothing built into Bepu, I think you have roll your own.

One way to implement it: Keep track of the triggers you are currently overlapping with, and in the next tick compare that list with the currently overlapping objects. Now, if one of your tracked triggers is no longer overlapping you can consider this as you OnTriggerEnd.
Yup.
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

Re: I want to make Trigger where should I look into.

Post by parapoohda »

thanks :D :D :D
Post Reply