Vehicle Vision Raycasting

Started by
-1 comments, last by Medo Mex 11 years, 5 months ago
What is the best approach to make the vehicle be able to detect enemies?

I thought about creating a large sphere, this sphere will detect collision to know who is around the tank, when the collision is detected with the large sphere, ray casting should start from the top of the tank to make sure that the tank can see who is colliding with the large sphere and that the enemy is not hiding behind walls, buildings, or any other mesh.

Is that the correct way? I have been having some troubles with vision ray casting, it's detecting a hit on the enemy even if the enemy is hiding behind the wall, here is the code that I'm using for vision ray casting:
btVector3 btRayFrom(eyePoint.x, eyePoint.y, eyePoint.z); // The point is exactly above the tank
btVector3 btRayTo(rayTo.x, rayTo.y, rayTo.z); // This is the point where the other model is located (perhaps enemy)
btCollisionWorld::AllHitsRayResultCallback allHitCallback(btRayFrom, btRayTo);
dynamicsWorld->rayTest(btRayFrom, btRayTo, allHitCallback);
if (allHitCallback.hasHit())
{
DWORD hitItemId;
int hitArrayIndex = -1;
for(int i = 0; i < allHitCallback.m_collisionObjects.size() - 1; i++)
{
hitItemId = (DWORD)allHitCallback.m_collisionObjects->getUserPointer();
// Ignore and go to the next index if it's hitting the tank itself
if (hitItemId != model->ID)
{
hitArrayIndex = i;
break;
}
}
if (hitArrayIndex >= 0)
// Hit!
else
// No hit
}


Keep in mind: The tank should be able to see the enemies through glasses, certain types of walls or anything that anyone can see through, but of course it should NOT be able to see the enemy through other types of walls, buildings, or most other meshes that the enemy can hide behind.

This topic is closed to new replies.

Advertisement