Jump to content

[SOLVED] Getting multiple ray intersections with physical bodies


photo

Recommended Posts

Posted

We need to get a list of all objects that a ray intersects with. But triangle perfect intersection is not what we want (we need it to be more tolerant), so we ruled out engine.world.getIntersections().

engine.physics.getIntersection() works perfectly, but the problem is that it returns only the first intersection with a physical body, not all intersections.

Is there any way of getting multiple intersections with physical bodies?

This is important for us so as to give a good selection experience in the RTS game that we are making.

 

Thanks,

Ashwin.

Posted

We need to get a list of all objects that a ray intersects with. But triangle perfect intersection is not what we want (we need it to be more tolerant)

 

Maybe engine.world.getIntersectionObjects with p0/p1 parameters defining a view frustum matching your intercection ray might give you a list of all intersecting objects. Unfortunately there is no Object engine.physics.getIntersection(vec3 p0,vec3 p1,int mask,Node exclude[],int ret[]) available, otherwise this approach could have been used.

Posted

Right now we are planning to go this way

1. Set N different collision masks for each different 'class' of objects

2. Perform N different collision tests using engine.physics.getIntersection(), tests ordered by selection priority of each class

3. First positive result is the winner (since we are ordering tests by priority)

 

Any obvious negatives?

Team Unigine - any chance of getting an engine.physics.getIntersections() function? :)

  • 2 weeks later...
Posted

Right now we are planning to go this way...Any obvious negatives?

Nope, it's a green light.

 

Or as it was already suggested, you can use engine.world.getIntersectionObjects() to get all objects from p0 to p1 and then simply filter out non-physical objects from the returned ones.

 

As another variant, you can use engine.physics.getIntersection() to get the first intersected object, offset from the returned intersection point by some short step and then trace the ray again.

×
×
  • Create New...