About Store Forum Documentation Contact



Post Reply 
Detecting when a grenade hits terrain
Author Message
Otolone Offline
Member

Post: #1
Detecting when a grenade hits terrain
Hi there!
The code below shows my attempt at detecting when a grenade hits world terrain.
Code:
bool grenade_hit = false;
Vec    grenade_position;
/*************************************************************/
class Item : Game.Item
{
   virtual bool update()
   {
      
      Vec start_pos = pos(), end_pos =pos() + matrix().pos.z*0.3;
      PhysHit physhit;
      if(name=="Grenade")
      {
        
         if(Physics.ray(start_pos, end_pos, &physhit))
         {
            D.text(0, 0.1, S + "Physics group: " + physhit.group);
            if(physhit.group==AG_TERRAIN)
            {
               grenade_hit = true;
               grenade_position = physhit.plane.pos;
               D.text(0, 0.2, "Terrain hit");
               D.text(0, 0.3, S+"Plane position: " + physhit.plane.pos);
              
            }
            
            
         }
      }
    
      return super.update();
   }
}
/***************************************************************/
The code does not work because I don't know how to set the terrain's actor group to AG_TERRAIN;like in the pseudo-code below:
World.terrain.actor.group(AG_TERRAIN)

Any suggestions or improvement on the code above are welcome!!
Thanks in advance.
P:S Detecting when grenade, character encounter water is also welcome.
03-18-2021 05:49 PM
Find all posts by this user Quote this message in a reply
Lancer Offline
Member

Post: #2
RE: Detecting when a grenade hits terrain
Hi,

maybe you can use
Code:
EE::Game::World.hmHeight();
and compare the hm height with your grenade height
03-19-2021 02:04 AM
Find all posts by this user Quote this message in a reply
Otolone Offline
Member

Post: #3
RE: Detecting when a grenade hits terrain
Thanks for the suggestion.
I will try that.
03-19-2021 06:44 AM
Find all posts by this user Quote this message in a reply
Post Reply