About Store Forum Documentation Contact
Donations:
345$/mo



Post Reply 
Unpredictable NavMesh Ray Casting
Author Message
fatcoder Offline
Member

Post: #1
Unpredictable NavMesh Ray Casting
I think I might have found a bug. I'm trying to cast a ray down through the world's navmesh to detect if a point is over the navmesh or not. Useful for determining if an agent is positioned inside or outside the walkable navmesh for example.

Anyway PathWorld.ray() appears to return completely unpredictable results, often producing a lot of false positives. I'm not sure if this is a bug or if I'm just using the function incorrectly. How does this function work and how should it be used?

I created a sample to show the problem. Open the Pathfind tutorial in the Game Basics folder. Then add the following code to the Draw() function... shouldn't matter where.

Code:
Vec pos, dir; ScreenToPosDir(Ms.pos(), pos, dir);
PhysHit phys_hit;
if(Physics.ray(pos, dir*D.viewRange(), &phys_hit))
{
   Flt hit_frac;
   Vec hit_pos, hit_normal;
   Vec start = Vec(phys_hit.plane.pos.x,  5.0f, phys_hit.plane.pos.z);
   Vec end   = Vec(phys_hit.plane.pos.x, -5.0f, phys_hit.plane.pos.z);
   if(Game::World.path().ray(start, end, &hit_frac, &hit_pos, &hit_normal))
      D.line(BLUE, start, end);
   else
      D.line(RED, start, end);
}

Now if you run the tutorial, you will see a vertical line protruding from the cursor position on the terrain. This line visualises the ray cast test. If the line turns blue, then the ray() function has detected a hit with the navmesh, otherwise the line is red. Holding down the space will show you the navmesh that is being ray cast against... just in case you forget.

If you try moving your mouse outside of the navmesh, the line will turn blue, which means the ray cast has detected a hit... this doesn't make sense... it is outside the navmesh, how can the ray hit it?

If you try moving the mouse around inside the navmesh, the line will change between red and blue randomly for no reason. This also makes no sense. I have a feeling this ray() function might be broken.
02-16-2012 02:59 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Unpredictable NavMesh Ray Casting
Hi,

raycast is used to detect collisions only when on surface against the walls
02-21-2012 12:38 AM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #3
RE: Unpredictable NavMesh Ray Casting
OK, I figured that might be the case. However, if you modify the code from my first post so that the ray goes horizontal across the nav mesh, it still reports false positives. Like this for example.

Code:
Vec start = Vec(5.0f,  phys_hit.plane.pos.y, phys_hit.plane.pos.z);
Vec end   = Vec(-5.0f, phys_hit.plane.pos.y, phys_hit.plane.pos.z);

It will still detect wall hits even when it does not pass through a wall. Very strange.
02-21-2012 02:10 AM
Find all posts by this user Quote this message in a reply
Salival Offline
Member

Post: #4
RE: Unpredictable NavMesh Ray Casting
Have same problem as fatcoder, It is quite often the ray failing in some areas.
(This post was last modified: 04-04-2012 03:48 PM by Salival.)
04-04-2012 02:49 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: Unpredictable NavMesh Ray Casting
by "wall" I meant edges of the navmesh
I've tested your code with applied change, and it works as expected.
04-15-2012 07:21 AM
Find all posts by this user Quote this message in a reply
Post Reply