Note: I have uploaded a video, at the bottom of this post, to show the problem in action.
I have a scene node which is supposed to move forward whenever the player is in its "field of vision" and stop when the player is not. The "field of vision" is a simple 3D line (not a cone or anything). So far, my code works correctly for the most part, except for one thing...
You see, here is how the scene node (the "guard" enemy, since this is a sort of spy game) determines whether the player is in its field of vision (all should make sense, and getVisionLine() is defined below):
Code: Select all
bool Guard::playerIsInFOV()
{
ISceneNode * nodeInVision = smgr->getSceneCollisionManager()->getSceneNodeFromRayBB(getVisionLine(), PLAYER | WALL);
if (nodeInVision && nodeInVision->getID() == PLAYER)
return true;
return false;
}
The problem here is that the "nearest" order is apparently being reversed.. or something (and I just tried switching the "start" and "end" of the field of vision line, and that didn't help). The guard is seeing the "wall" as the closest node, even when the player is between the wall and the guard. You can see this in the video at the bottom of this post (as I said earlier, the guard is supposed to move forward whenever it "sees" the player).
For the sake of completion, here is the less important getVisionLine() function, which calculates the field of vision (which, as I stated earlier, is simply a 3D line, not a cone or anything complicated):
Code: Select all
line3df Guard::getVisionLine()
{
vector3df guardPosition = node->getPosition() + vector3df(0, 10, 0); // y is increased by 10 so that the line starts just below the guard's eyes, not at its origin
line3d<f32> visionPath(guardPosition, guardPosition + (vector3df(500, 0, 10)));
return visionPath;
}
YouTube upload of the problem in action: http://www.youtube.com/watch?v=H9-WGXpCdX8