playMaker

Author Topic: [SOLVED] AI Health system  (Read 4757 times)

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
[SOLVED] AI Health system
« on: January 05, 2013, 04:42:21 PM »
Hi! I realise that i have asked this before, but i never found any solution so here goes again (at least this is for a new project)

It's weird how it is with AI health systems - it seems that everyone are using them but i just cannot find ANYTHING about how to make them anywhere on the internet =/

That being said, what i need is a way to have an enemy prefab where i can spawn 10 of them and each one will have their own health

I've been trying to wrap my head around it for so long it's doing my head in!

I've tried using a global variable called enemyHealth that i then take away from when i shoot them but the problem with global vars is that All 10 of the prefabs that i spawned will use that variable and that means that they all share the same health pool..

How can i be smart about doing this? I had a look at targetPro, but as far as i can see it's only useful for things like turrets and other AI stuff

halp pls =(

-Koztheboss
« Last Edit: January 06, 2013, 12:39:10 PM by KozTheBoss »
Remember, you don't fail unless you give up trying to succeed!

Horror

  • Junior Playmaker
  • **
  • Posts: 79
Re: AI Health system
« Reply #1 on: January 05, 2013, 09:28:06 PM »
Make an FSM for your enemy prefab to handle damage and create a private int variable in that FSM (from the main playMaker editor window, not the global window). Each enemy will have it's own health pool if you do it this way.

cdillard

  • Playmaker Newbie
  • *
  • Posts: 18
Re: AI Health system
« Reply #2 on: January 06, 2013, 09:26:57 AM »
Try giving each enemy its own variable for health. If you already have your health system set up globally with your gui, just have the enemy update the global variable on hit with its own.

I had something completely set up in playmaker like this on a game I previously abandoned and you don't need anything other than playmaker. You just use a gameManager gameobject to control the gui itself and give each enemy a int value for health. The gameManager is what controls all the gui events. When you hit the enemy, his/her/its (whatever) health int value is sent to the manager which then adjusts the gui value accordingly. You can even set a guiTexture assigned to the enemy for portraits and names if you want and send those to the manager as well.

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: AI Health system
« Reply #3 on: January 06, 2013, 09:55:58 AM »
Hi,

first of all thanks for the responses :)

I'm about to mess around with this now - Horror, what do you mean the "main" playmaker window and not the global one? do you mean a local variable instead of a global one? if it's a local variable on each prefab then the "bullet" prefab can't access the variable to change the health.. nor the healthmanager gameobject if i make it through one of those

Let me mess around with a couple of possibilities and i will report back here later
Remember, you don't fail unless you give up trying to succeed!

cdillard

  • Playmaker Newbie
  • *
  • Posts: 18
Re: AI Health system
« Reply #4 on: January 06, 2013, 10:25:23 AM »
Well, when the bullet collides, you use the local var to set the global one.

Game Manager has 100 Health. Full bar. Displayed on screen.

Soldier A has 100 Health. Bullet hits him.

Bullet causes FSM to adjust local variable to 90 Health. This variable is now passed to Game Manager.

FSM is called on Game Manager using variable passed from the Soldier and the GUI is updated.


KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: AI Health system
« Reply #5 on: January 06, 2013, 11:20:43 AM »
aaaaah i see what you mean, i think!

So when the bullet with raycast detects that it has hit an enemy, it saves the hit target object as a GO variable "targetHit" and uses a sendEvent to that specific enemy - the enemy then adjusts it's own health var?

Will it work from the bullets POV to store targethit as a var and then send an event to that specific enemy?

BTW im not building GUI elements yet - I just need for the enemys to have their own health and be able to kill them individually
______________________________________________________________________________
EDIT:

looking back, im pretty sure i tried that before (saving the object hit as a variable and then sending an event to that specific enemy) and it didn't work - the variable didn't reference the specific enemy that i hit =(

Im so confused =(

_____________________________________________________________________________

I think the problem is that i have the hit-detection on the bullet - the bullet uses raycast to see if it hit a target and then compares that target to the tag "enemy" - if target hit = enemy then send an event to that enemy gameobject (which is not possible)

but how do i make the zombie itself have hit detection? I find that using colliders is very unreliable when the bullet moves fast, so a raycast from the bullet is much better at detection objects hit
« Last Edit: January 06, 2013, 11:27:19 AM by KozTheBoss »
Remember, you don't fail unless you give up trying to succeed!

cdillard

  • Playmaker Newbie
  • *
  • Posts: 18
Re: AI Health system
« Reply #6 on: January 06, 2013, 11:25:22 AM »
Yeah that will work. You just do a collision test on the enemy and when a collision with the bullet occurs, fire off an event.

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: AI Health system
« Reply #7 on: January 06, 2013, 11:28:47 AM »
I find that using colliders is very unreliable when the bullet moves fast, so a raycast from the bullet is much better at detection objects hit

does collider detection work well for you? last time i tried it, the bullet moved so fast that it flew right through the enemy without detection a hit most of the time =(
Remember, you don't fail unless you give up trying to succeed!

cdillard

  • Playmaker Newbie
  • *
  • Posts: 18
Re: AI Health system
« Reply #8 on: January 06, 2013, 11:32:26 AM »
Even with collision detection set on continuous dynamic? You could always set your collider to be longer for more of a chance to trigger. Or try it in reverse...Set a FSM on the character and wait for collision from the bullet. Then fire off your events then.

cdillard

  • Playmaker Newbie
  • *
  • Posts: 18
Re: AI Health system
« Reply #9 on: January 06, 2013, 11:33:56 AM »
Also, raycasts are very expensive. If you have a lot of bullets on screen doing raycasts left and right, your performance is bound to suffer.

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: AI Health system
« Reply #10 on: January 06, 2013, 12:37:54 PM »
Thanks for your help! I tried my luck with collision boxes again and it works flawlessly :)

I also have a detector on the bullet, so when it hits something it destroys itself

Can't believe it was that simple and i've been making it so hard on myself.. =(

Thanks for the help! :)

-koztheboss
Remember, you don't fail unless you give up trying to succeed!