CastRay in C++ not returning true? Reasons
by Terence Tan · in Torque Game Engine · 07/03/2006 (8:20 pm) · 1 replies
Hi,
I have been trying to get the AI to use the waypoint system but have run into a snag. What I was assuming is that if the player leaves an AI LOS, the monster should seek a waypoint in order to try to navigate around an obstruction.
www.posdreams.com/xraytork.jpg
Obvious the kork circled should not be able to see the player. The standard code lifted straight from AIPlayer doesn't seem to work, cast Ray always seems to return false.
1. Checked if wall object has got collision box and is TSStatic
2. Checked coordinates and Target Object. Looks ok
3. Tried using just a ray trace from position to position, doesn't work?
I'm pretty clueless now why it shouldn't work? Seems like it's some that should be basic...but not sure what else I can do..
I have been trying to get the AI to use the waypoint system but have run into a snag. What I was assuming is that if the player leaves an AI LOS, the monster should seek a waypoint in order to try to navigate around an obstruction.
www.posdreams.com/xraytork.jpg
Obvious the kork circled should not be able to see the player. The standard code lifted straight from AIPlayer doesn't seem to work, cast Ray always seems to return false.
MatrixF eyeMat;
Point3F location;
// getEyeTransform(&eyeMat);
// eyeMat.getColumn(3,&location);
location = getPosition();
// Point3F targetLoc = mTargetObject->getBoxCenter();
Point3F targetLoc = mTargetObject->getPosition();
// This ray ignores non-static shapes. Cast Ray returns true
// if it hit something.
RayInfo dummy;
if (getContainer()->castRay( location, targetLoc,
InteriorObjectType | StaticShapeObjectType | StaticObjectType |
TerrainObjectType, &dummy))
{
if (mTargetInLOS)
{
throwCallback( "onTargetExitLOS" );
mTargetInLOS = false;
}
}
else
if (!mTargetInLOS)
{
throwCallback( "onTargetEnterLOS" );
mTargetInLOS = true;
}1. Checked if wall object has got collision box and is TSStatic
2. Checked coordinates and Target Object. Looks ok
3. Tried using just a ray trace from position to position, doesn't work?
I'm pretty clueless now why it shouldn't work? Seems like it's some that should be basic...but not sure what else I can do..
About the author
Torque Owner Terence Tan
Has anybody got any experience with complex collision boxes on TSStatic objects cause issues with ray tracing? It seems if the object is even a little more complex, ray casts and project go right through it. There NO problem with player/character collisions though.