playMaker

Author Topic: [solved] RPG / Grenade blast  (Read 863 times)

heavygunner

  • Sr. Member
  • ****
  • Posts: 344
[solved] RPG / Grenade blast
« on: June 22, 2020, 04:26:32 AM »
Hello !

Working on Tower defense game. I wanna kill all zombies within radius from rpg / grenade impact point.

how to do it ?

Thanks
« Last Edit: July 06, 2020, 03:14:18 AM by heavygunner »

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: RPG / Grenade blast
« Reply #1 on: June 22, 2020, 11:16:11 AM »
Well an easy way to do it would be a trigger.

You likely want to have an explosion particle spawned on the spot anyway, so;

1) In that same object (or child of it) place a regular sphere. Resize it to the area you want to blow up. Give it a tag, like 'explosion' or something.
2) Set it's collider as a trigger and turn the mesh renderer off. You will also need to add a Rigid Body component to the object. Turn the gravity off and set it to Kinematic.
3) Use and FSM to do a short wait and then deactivate the whole prefab with the particles, or just the sphere if you want the effects to linger longer than the blast detection.
4) Your enemy also needs a trigger collider. It doesn't need to have a rigid body because the explosion sphere does.
5) Have an FSM on for your enemy which is using a Trigger Event, which is looking for the tag you made (my example was 'explosion').
6) The event goes to where you deal your damage or kill the enemy outright just for being hit at all.

Now the most simple version is that being touched is instant death for the enemy. However you can add to it so the edge of the blast hurts less than the center. You can do this by storing the object that set off the Trigger Event (the sphere) and then getting the distance to it. That distance will be taken from it's center. You could make it so it checks for say 3 distance brackets (maximum damage, medium damage, little damage) or use it with some kind of math formula to work directly on the maximum damage.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: RPG / Grenade blast
« Reply #2 on: June 22, 2020, 02:06:39 PM »
Hi.
you can try 'Overlap Sphere' it will get all object within the set sphere and place them into an array then you can loop thru and do what you need to do with them.

'Get Next Physics Overlap Sphere' could work as well then you don't need an array, but i have not tested it and might be harder to debug with it.