playMaker

Author Topic: Throw grenade at bad guy  (Read 4640 times)

terrymorgan

  • Junior Playmaker
  • **
  • Posts: 65
Throw grenade at bad guy
« on: May 06, 2012, 12:01:20 PM »
I've been studying this fpskit

http://armedunity.com/forum/download/FPSKitV1.2.rar

Because it's the only unity project with actual bad guys attacking me that also includes
the source code I could find.  I got the beast into my throw grenade scene (with a lot of commenting out)
but now I need some clues as to how to get the player and beast to take damage, not
necessarily by FSM.

exe file
http://terrymorgan.net/unity3d/throw_grenade_at_bad_guy.zip
11mb

unity package
http://terrymorgan.net/unity3d/throw_grenade_at_bad_guy.unitypackage
4mb
The unitypackage actually works in an empty project (if you have character controller and playmaker pkg's also.

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Throw grenade at bad guy
« Reply #1 on: May 06, 2012, 05:50:29 PM »
One approach is that when the grenade explodes it would use a "send event" action and broadcast an event such as "take damage" which would be a global transition state on your player character. (ideally in its own seperate "damage" fsm)

When you jump to that state, you would then check if the grenade is close enough to do damage and how much.  Then subtract that from your players health.


terrymorgan

  • Junior Playmaker
  • **
  • Posts: 65
Re: Throw grenade at bad guy
« Reply #2 on: May 08, 2012, 10:25:23 AM »
When you jump to that state, you would then check if the grenade is close enough to do damage and how much.  Then subtract that from your players health.

The player is throwing the grenades, how do I inflict damage on the beast? My other thought is to
put the playmaker stuff I know into fpskit, it has the shooting bad guys thing going well, vehicles, etc., but
no dialogue, inventory, puzzles. Either way is a lot of work.

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Throw grenade at bad guy
« Reply #3 on: May 08, 2012, 11:02:41 AM »
Here's a basic setup to inflict damage on an enemy.

(Player)
State 1 (get key down action) connected to State 2 (create object "grenade") connected back to state 1 (so you can loop it)

(Grenade)
state 1 add force (in Z axis so it goes forward) connected to state 2 (wait - for like 5 seconds before exploding)
connected to state 3 (destroy self action) and a (send event action) with the setting set to "broadcast all"
and make a global event called "take damage"

(Enemy)
state 1 (waiting for damage and checking grenade distance) - we need to check if the enemy is close enough to the grenade to take damage so add a (get distance action) and store that in a new float variable - make sure to check "every frame" so that its constantly checking that value

state 2 (not connected to any other state) - add a global transition called "take damage" to this state by right clicking on it and pick "add global transition" then right click that new dark box and choose "take damage" or whatever you named it earlier

Now add a (float compare action) and compare the distance from the grenade variable and whatever blast radius value you want to use eg: 3
If its less than 3 - goto state 3
If its greater than - goto state 2 again

State 3
Now add a, int variable called "health" to the enemy
And in state 2 add an (Int add action) and subtract how much damage you want to cause the enemy to take
also add a (int compare action) and compare the health variable to 0
If equal to 0 then goto state 3 which would have a (destroy self action) to delete the enemy once his health is zero


So to recap (sorry for no pictures right now) - Player fires created a grenade, which waits 5 seconds before exploding.  When it explodes it signal all enemies in the game to check how far away they are from the grenade and if they are close enough then they "take damage" by jumping to that global transition state in their own FSM and apply damage to themselves.

This way no matter how many enemies there are, they all have self contained damage taking information.  As you add more and more weapon types all you have to do is all one extra state that checks which type of weapon its being hit by, and change the "damage" variable to determine how much it gets hurt, super simply to tweak and fully expandable as the scope of your game grows.

I'll try and put together a video tutorial this weekend to explain this in video.

terrymorgan

  • Junior Playmaker
  • **
  • Posts: 65
Re: Throw grenade at bad guy
« Reply #4 on: May 08, 2012, 11:21:26 AM »
quote
I'll try and put together a video tutorial this weekend to explain this in video.
unquote
That would be great

I'm still having problems with your 3rd person controller, he doesn't seem to go into the run state
http://terrymorgan.net/3rd_person_justifun.unitypackage