Author Topic: checkForCollisionSpherical for small sphere  (Read 2784 times)

Offline grog

  • byte
  • *
  • Posts: 19
    • View Profile
checkForCollisionSpherical for small sphere
« on: April 08, 2013, 11:26:33 pm »
I have a large mesh that I use for a level and multiple smaller meshes representing players that reside within it.  The players collide with each other and the map without issue, using a mix of ellipsoid and spherical checks.  I also have even smaller meshes that I was using for grenades, but the spherical collision detection is not working consistently for these unless I use a radius that is way too large.  Basically, using checkForCollisionSpherical with radius 0.5, sometimes the grenades collide with the walls/floor correctly, but other times they pass straight through without registering a collision.  The same things happens with ellipsoid collision at the same size. If I up the radius to 1, every collision is detected, but the result looks bad because the grenade reacts before it visually hits the wall and floats above the floor due to the too-large sphere. If I decrease the radius (say 0.3), no collisions are detected.

I tried checking the docs for some config settings that might help, but I don't see anything that obviously relates to this.  Playing with Config.collideOffset didn't seem to make a difference. I would appreciate any help/ideas.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: checkForCollisionSpherical for small sphere
« Reply #1 on: April 09, 2013, 08:23:00 am »
For spherical collision detection, this might happen because the algorithm only takes start and end point into account. If the radius is small and the transition is large in comparison, neither might indicate a collision. However, this shouldn't be a problem when using ellipsoid collision detection...have to tried to subdivide the translation? How long is the translation vector? It might happen, that a rough check at the beginning of the collision detection fails if the radius is small compared to the translation's lenght, but i'm not sure...

Offline grog

  • byte
  • *
  • Posts: 19
    • View Profile
Re: checkForCollisionSpherical for small sphere
« Reply #2 on: April 09, 2013, 08:39:22 am »
Ahh, that's good to know about the spherical algorithm. Makes sense now why it's not quite working for me.  Hmm, I might have to take another look at ellipsoid, or maybe I can subdivide the translation like you say.  Thanks much!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: checkForCollisionSpherical for small sphere
« Reply #3 on: April 09, 2013, 03:26:54 pm »
If sub-dividing helps, please let me know. I'll then look into a way to fix this problem in the engine itself.

Offline grog

  • byte
  • *
  • Posts: 19
    • View Profile
Re: checkForCollisionSpherical for small sphere
« Reply #4 on: April 09, 2013, 09:16:16 pm »
Ok, so I adjusted my method to subdivide the translation vector based on the radius of the sphere and make successive calls to checkForCollisionSpherical() until the entire desired movement length is reached.  So far, everything seems to be working perfectly.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: checkForCollisionSpherical for small sphere
« Reply #5 on: April 09, 2013, 09:50:10 pm »
I see...i'll have a look if i can find the reason for it to fail for larger translations in your case. I think it's one of the early-out optimizations that triggers where it shouldn't...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: checkForCollisionSpherical for small sphere
« Reply #6 on: April 10, 2013, 09:08:55 pm »
One short question: Can you post some values for your ellipsoid and your translation for a case where it doesn't work?

Offline grog

  • byte
  • *
  • Posts: 19
    • View Profile
Re: checkForCollisionSpherical for small sphere
« Reply #7 on: April 10, 2013, 10:08:09 pm »
I just tried an older version of my code when I used the ellipsoid method to see if I could pull a specific movement vector when the collision didn't register.  My ellipsoid was a SimpleVector of (0.5, 0.5, 0.5), and the translation vector was (0.222294,-0.29999998,-1.4834371).  With these values, the grenade passed through a plane undetected.

Also failed for translations:
(-1.2741067,-0.29999998,-0.79161346)
(0.83904916,-0.29999998,-1.2433811)

Hope that is at all useful.  I can't really see any consistency between when it works and when it doesn't on my end.  Getting those values just consisted of randomly throwing grenades at different spots until one went through a wall, although once I found a spot all subsequent grenades do pass through undetected as well.
« Last Edit: April 10, 2013, 10:20:24 pm by grog »