My class is Projectile, and I can decide whether that projectile is explosive or not (bExplosive).
The difference between explosive or not, is that when a player is hit, a function called Explode() gets called, and the FHitResult of the Impact is passed.
Now, I have used this class to make the Rocket_Projectile subclass. The Rocket is a projectile with these properties:
When a player is hit, it applies **full **damage
When an object is hit, it applies **radial **damage
Until here, no problems.
The problem comes because the Rocket has a lifetime. That means, after a certain ammount of time, the Rocket explodes by itself applying a radial damage.
But the Explode() function needs a FHitResult… but I don’t have any HitResult to pass!
In my Explode() class I have some logic to be applied when the Rocket explodes, so it’s really necessary it is called
This is kind of what I do… I’m not sure if it helps. The example has a dude firing a “rocket”, exploding on contact and doing radial damage. If you hit the guy, he dies from radial damage.
You could also do what I do, which is to also pass in a bool that tells the projectile whether to ‘search’ for a nearby surface and use that as the explosion point, doing a sphere ovelap test. I use this when things explode very close to the ground for example, and I still want to leave a decal / explosion particle there.
Well you’d have to add a sphere component to the grenade (or use an existing one), and when it detects an overlap, cast the actor to see if it’s a character. If it is, explode.
You’ll likely want to inherit from the projectile class to make a grenade.