Jump to content
  • Advertisement
Sign in to follow this  
Medo Mex

Vehicle Vision Raycasting

This topic is 2208 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
if (hitArrayIndex >= 0)
// Hit!
// 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. Edited by Medo3337

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!