Line of sight check error
by Tony Oakden · in Torque Game Engine · 03/08/2005 (2:28 pm) · 7 replies
Applogies to those who have seen this post before. I posted it in public by mistake a while back.
Anyway...
I've come up against a wierd bug in the line of sight check.
I've got a BSP space with several seperate BSP platforms inside it. I made the platforms seperately so that I could move them about in the world editor and so tune my game easier. I use the line of sight check demonstrated in aiplayer.cc to check if my AI can see the player:
getContainer()->castRay( location, targetLoc,
InteriorObjectType | StaticShapeObjectType | StaticObjectType |
TerrainObjectType, &dummy)
where:
location = location of the AI
TargetLoc = location of the Player
This seemed to work fine at first with simple blocky BSP spaces. But now I've found that sometimes my AI can see the player through the thinner platforms. I've double checked and location and targetLoc are set up correctly and the platforms are definetly there as the player and AI are interacting with them in physics. But the AI are trying to attack the player through the platforms.
Now here is the really weird bit. If I scale the platforms to be slightly thicker in the editor (just a y scale of 1.1 is enough) the AI sees them just fine. Also if I half the thickness of them in Quark and then double them in the game world so that the net thickness is back to the same as above the problem also goes away :P !
Later I replaced the BSP platforms with simple blocks created in milkshape but the bug still occurs. E.g. AI can see my player through the thinner platforms. If I scale them up they see them fine. Physics always collides with the platforms though so I think it must be something specific to the LOS check.
This seems like if might be something to do with the way in which the line of sight code steps through the scene graph. Maybe a problem of resolution which means that at certain spacings the check skips over the platforms? I don't know how the routine works so I'm just guessing here :)
Has anyone else noticed this behaviour and maybe tracked down the cause? I haven't made any changes to castRay so I can't imagine it's anything I've done. With the scaling decribed above I seem to be able to work around this but it would be much better if I knew what was going on.
regards,
Tony Oakden
Anyway...
I've come up against a wierd bug in the line of sight check.
I've got a BSP space with several seperate BSP platforms inside it. I made the platforms seperately so that I could move them about in the world editor and so tune my game easier. I use the line of sight check demonstrated in aiplayer.cc to check if my AI can see the player:
getContainer()->castRay( location, targetLoc,
InteriorObjectType | StaticShapeObjectType | StaticObjectType |
TerrainObjectType, &dummy)
where:
location = location of the AI
TargetLoc = location of the Player
This seemed to work fine at first with simple blocky BSP spaces. But now I've found that sometimes my AI can see the player through the thinner platforms. I've double checked and location and targetLoc are set up correctly and the platforms are definetly there as the player and AI are interacting with them in physics. But the AI are trying to attack the player through the platforms.
Now here is the really weird bit. If I scale the platforms to be slightly thicker in the editor (just a y scale of 1.1 is enough) the AI sees them just fine. Also if I half the thickness of them in Quark and then double them in the game world so that the net thickness is back to the same as above the problem also goes away :P !
Later I replaced the BSP platforms with simple blocks created in milkshape but the bug still occurs. E.g. AI can see my player through the thinner platforms. If I scale them up they see them fine. Physics always collides with the platforms though so I think it must be something specific to the LOS check.
This seems like if might be something to do with the way in which the line of sight code steps through the scene graph. Maybe a problem of resolution which means that at certain spacings the check skips over the platforms? I don't know how the routine works so I'm just guessing here :)
Has anyone else noticed this behaviour and maybe tracked down the cause? I haven't made any changes to castRay so I can't imagine it's anything I've done. With the scaling decribed above I seem to be able to work around this but it would be much better if I knew what was going on.
regards,
Tony Oakden
#2
03/10/2005 (3:36 pm)
If two of us come up against this virtually at the same time then surely someone else must have noticed this behaviour before?
#3
03/10/2005 (3:42 pm)
I've seen it before myself, just figured it was shooting through the textures on my models since they had a transparent alpha layer, kinda like looking at someone through the cracks in the brickwork.
#4
03/21/2005 (3:06 pm)
No these are solid platforms with no alpha in the texture or even a texture in some cases.
#5
03/21/2005 (9:39 pm)
Surely someone has some insight into this problem?
#6
Strangely, having a complicated collision mesh broke it unless the line went simultaniously through all parts of the collision mesh (As in a corner between two points). Breaking up stuff like a drawer into several parts with individual collision had castRay working how it should. Check if your collision models have multiple parts such as:
|___ : Two rectangles for a drawer.
Which could be modeled as two models.
might help. here's hoping.
03/22/2005 (4:52 pm)
How we fixed it:Strangely, having a complicated collision mesh broke it unless the line went simultaniously through all parts of the collision mesh (As in a corner between two points). Breaking up stuff like a drawer into several parts with individual collision had castRay working how it should. Check if your collision models have multiple parts such as:
|___ : Two rectangles for a drawer.
Which could be modeled as two models.
might help. here's hoping.
#7
03/22/2005 (6:07 pm)
Thanks Phillip. The shapes I am using are modelled as simple rectangles but I am relying on Milkshape to autocreate hte bounding box so I guess it is possible it's screwing up somewhere. I'll try manually creating a simple bounding box for each shape to see if that helps.
Torque Owner Philip Bloom
Wow, timing.
I'm having the exact same problem with DTS files and gServerContainer.castRay going right through them without seeing them. I dove through the code last night for a while because I need that function working for my mouse picking (a modified click n Pick) to work. It appeared that the point.interpolate was interpolating past the object. But I could be wrong as well, combining the math and the container optimizations, I had trouble reading it.
I really need help on this though as I need to be able to make sure that if a ray goes through, it detects what is along that ray. I tried to reduce the ray length in the assumption that the detail was afactor of ray length, but that didn't seem to work (dividing by 20 didn't really change it's ability to detect).
If this fix works, it's ugly, but I guess we could use that. But I'd prefer to figure out what's going on with the castRay. Is there anyone who has the knowhow on this function to save me tons of work crunching it to figure out where it's going wrong?
Aside: Doesn't this belong in the engine section since castRay is c code? oh well.
I hope someone can help because I think at the moment smashing that bit and reworking it may be atouch out of my league.