Game Development Community

Weird Raycasting Behavior

by Robert Fritzen · in Torque 3D Professional · 03/15/2014 (12:49 pm) · 5 replies

So, I've gotten extremely ahead of schedule on my latest pack addon, and you know, I can almost always expect something like this to come up when I get ahead, a problem in which I have no idea wtf is going on or how to fix it per say.

For some, unknown reason, my raycast in C++ is absolutely failing on all levels.

bool AdvancedAIPlayer::hasLosTo(ShapeBase *obj) {
   if(obj == NULL) {
      return false;
   }
   S32 trgID = obj->getId();
   .
   .
   .
   U32 colMask = TerrainObjectType | StaticObjectType;

   RayInfo rinfo;
   disableCollision();
   if(gServerContainer.castRay(startPos, endPos, colMask, &rinfo) == true) {
      enableCollision();
      if(rinfo.object == NULL) {
         return false;
      }
      return rinfo.object->getId() == trgID;
   }
   enableCollision();
   return false;
}

For some unknown reason, the castRay statement only executes when I place an object between myself and the player, and then it returns the object in between. Any ideas?

#1
03/15/2014 (2:42 pm)
Robert,

I vaguely remember an issue with my AI when it came to understanding, transitioning etc on terrains. For whatever reason terrains cause issues. See if you can change the terrain to some other object type and see if the behavior, at least, improves.
#2
03/15/2014 (4:59 pm)
My original testing was done on a map without a terrain, so I doubt that to be the cause.

If it helps at all, I'm noticing that my ShapeNameHud is rendering objects through walls, so perhaps it's an issue on my end. I'll have to do some more investigation. If anything is sticking out however, please let me know as it's important I get this fixed.
#3
03/15/2014 (8:41 pm)
Robert,

I am curious of a possible issue that I thought could happen regarding LOS of AI using the raycast. What types of walls are you using (class). If a model does not have a boundsbox or proper collision meshes set I am wondering if this effects the LOS. The AI should not be able to see through walls and this is an issue I put on the back burner as I was currently getting AI friends to follow when asked.
I remember the onStuck function not being called when I mixed terrain and static meshes. They would just continue to attempt to move forward to the set destination (They looked like they were not moving at all) without ever calling this function. So I am assuming there is something different with terrain collisions. I will keep thinking about this to see if I can come up with an angle that I am missing. BTW, keep up the great work; I am grateful you are in the community.
#4
03/16/2014 (9:27 am)
I think there's a slight mis-understanding here regarding the problem occurring. I'm not at all interested in walls between the AI and the player. What's concerning me is the problem of the raycast not identifying the player object when there's absolutely nothing between the player and the AI. I have collision disabled on the AI so it's not hitting itself, and the only time the raycast is returning a "hit" is when I place something between me and the AI.

I'm wondering if this is either a problem with the raycast, or if for some unknown reason, they removed PlayerObjectType from being a part of StaticObjectType.

EDIT: I'm a complete n0b, lol.... It would help if the raycast was actually checking for the object type I was interested in... Solved.
#5
03/16/2014 (9:59 am)
lol - was gonna ask but I figured you'd have checked that. Glad to see it works "as designed" if not quite "as used"....