Sign in to follow this  
Medo Mex

Vehicle Vision Raycasting

Recommended Posts

Medo Mex    891
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:
[CODE]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[i]->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
}
[/CODE]

[b]Keep in mind:[/b][i] 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.[/i] Edited by Medo3337

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this