Jump to content

  • Log In with Google      Sign In   
  • Create Account


Vehicle Vision Raycasting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 25 November 2012 - 05:30 PM

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[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
  }

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, 26 November 2012 - 12:49 AM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS