Otolone
Member
|
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 |
|
Lancer
Member
|
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 |
|
Otolone
Member
|
RE: Detecting when a grenade hits terrain
Thanks for the suggestion.
I will try that.
|
|
03-19-2021 06:44 AM |
|