Using a DetectorVolume with Kinetic Entities

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
ntd master
Posts: 10
Joined: Wed Nov 24, 2010 9:29 pm
Location: United States
Contact:

Using a DetectorVolume with Kinetic Entities

Post by ntd master » Mon Oct 24, 2011 6:10 am

Hey guys,

I have a scenario where I have one box shaped DetectorVolume that doesn't currently move, and one box shaped kinetic entity that I can control with user input and move around. I'd like to detect and have an event go off whenever the kinetic entity does any kind of colliding with the DetectorVolume.

The problem I'm having is the only time a collision is being detected is when the center position of the kinetic entity is inside of the DetectorVolume. So if part of the kinetic entity is inside of the DetectorVolume, but the exact center of the entity isn't, then it's acting like there's zero collision. Any idea what might be going wrong here? Is this a bug? It seems like the event EntityBeginsTouching is actually doing the same thing as VolumeBeginsContainingEntity.

I took a look at the DetectorVolumeDemo and that seems to be working perfectly fine, which is leading me to think I'm probably doing something weird here.
Follow on Twitter: Vulture Games
Official Website: Vulture Games Studio, LLC

Norbo
Site Admin
Posts: 4772
Joined: Tue Jul 04, 2006 4:45 am

Re: Using a DetectorVolume with Kinetic Entities

Post by Norbo » Mon Oct 24, 2011 6:23 am

To isolate the problem, what happens if you just pull the mesh in question over into the BEPUphysicsDemos and make the DetectorVolumeDemo use it? If that reproduces the issue, it could just be something about the mesh which confuses the detector volume system (maybe an issue with winding, lack of mesh watertightness, or possibly some numerical tolerance gone awry). In this case I could take a look and see if I can do anything about it.

What you describe sounds like the volume isn't finding any triangles in the vicinity of the shape, but the ray cast is still working as expected so containment is defined by the entity's position.

Norbo
Site Admin
Posts: 4772
Joined: Tue Jul 04, 2006 4:45 am

Re: Using a DetectorVolume with Kinetic Entities

Post by Norbo » Mon Oct 24, 2011 6:29 am

Another specific thing to look at is collision rules. Maybe collision rules aren't used consistently somewhere in the detector, leading to a 'partial' detection.

Norbo
Site Admin
Posts: 4772
Joined: Tue Jul 04, 2006 4:45 am

Re: Using a DetectorVolume with Kinetic Entities

Post by Norbo » Mon Oct 24, 2011 6:34 am

Never mind about the collision rules bit- it appears they are completely unused by the DetectorVolume :)

I'll fix that in the development version soon, though it won't address your issue.

ntd master
Posts: 10
Joined: Wed Nov 24, 2010 9:29 pm
Location: United States
Contact:

Re: Using a DetectorVolume with Kinetic Entities

Post by ntd master » Mon Oct 24, 2011 7:06 am

Hey Norbo,

It looks like I might have found the issue. I was moving the kinetic entity around by updating it's world transform every update, instead of just trying to move it around purely using velocities. After doing a quick test with only velocity based movement, it looks like it's detecting collision the way I'd expect it to.

That's really the only difference between my code and the demo code (which I'm guessing turns out to be a big difference). I knew that forcibly re-positioning a kinetic entity could cause squishy issues regarding collision response, but I guess I wasn't aware that it could even cause problems with more basic collision detection. I'm surprised though, since that doesn't require collision response behaviors, but more or less just overlap detection.
Norbo wrote:To isolate the problem, what happens if you just pull the mesh in question over into the BEPUphysicsDemos and make the DetectorVolumeDemo use it?
The mesh seems to work fine in the demo, so it makes me think even more that I just need to stop moving things via position and just use velocities from now on. I wish moving kinetic objects using position wasn't so convenient, then maybe I wouldn't keep getting lured back into using it.
Norbo wrote:If that reproduces the issue, it could just be something about the mesh which confuses the detector volume system (maybe an issue with winding, lack of mesh watertightness, or possibly some numerical tolerance gone awry). In this case I could take a look and see if I can do anything about it..
The winding and lack of mesh tightness were my thoughts too initially, but after switching from my complex mesh to a simple code-made box I saw I was still having the same issue.
Norbo wrote:Never mind about the collision rules bit- it appears they are completely unused by the DetectorVolume :)

I'll fix that in the development version soon, though it won't address your issue.
Haha, yeah I fooled around with that earlier and it started tossing null exceptions my way. I was like, "I've been tricked!"

In any case, I should be good for the moment, but I'll let you know if I run into the same issue again.
Follow on Twitter: Vulture Games
Official Website: Vulture Games Studio, LLC

Norbo
Site Admin
Posts: 4772
Joined: Tue Jul 04, 2006 4:45 am

Re: Using a DetectorVolume with Kinetic Entities

Post by Norbo » Mon Oct 24, 2011 7:28 am

I was moving the kinetic entity around by updating it's world transform every update, instead of just trying to move it around purely using velocities.
For the detector volume specifically (and indeed, collision detection in general), that should actually work fine. The detector volume works entirely on the last frame's stored containment state and the current frame's detected collision state, which is defined entirely by the location and orientation of the collision shape.

Another possibility: if the bounding box is somehow not being updated or the entity is otherwise unfindable by the broad phase query accelerator, the DetectorVolume would not detect anything.
Haha, yeah I fooled around with that earlier and it started tossing null exceptions my way. I was like, "I've been tricked!"
A new development version is now available that removes the deception :)

ntd master
Posts: 10
Joined: Wed Nov 24, 2010 9:29 pm
Location: United States
Contact:

Re: Using a DetectorVolume with Kinetic Entities

Post by ntd master » Mon Oct 24, 2011 7:56 am

Ah, so I wasn't completely just making things up in my head (always a good thing).
Norbo wrote: Another possibility: if the bounding box is somehow not being updated or the entity is otherwise unfindable by the broad phase query accelerator, the DetectorVolume would not detect anything.
Hm...I don't think that was happening but it's something to watch out for.
Norbo wrote:A new development version is now available that removes the deception :)
Awesome.
Follow on Twitter: Vulture Games
Official Website: Vulture Games Studio, LLC

Post Reply