How to count health value for spawn objects?

Hi! Everyone,
I’m trying to creat a robots shooting game, I spawned 5 of them in loop, expect to shoot them for 5 shots to destroy them by each, the result is they were killed simultaneously when one of their health value down to zero, like they share the same variable after being spawned, I thought it can be done by assigning ID for a variable named “health” to trigger a destroyed event when health value is down to or under zero in original logic tree, the random values within seems work fine separately, how come the health variable become global after being spawned, what’s the catch? It failed even I count health value using object property, what’s the right way to achieve it?

1 Like

Hi @olsen

I am not sure how your logic was created, but here I have made a simple game to show how it could be done. In this game, use space to randomly spawn cubes and then shoot them 5 times with left mouse button to destroy them.

here you can find the web version of the example.

Along with game description and Blend file.

Hope this helps,

Best,
QC

4 Likes

Hi,@QuantumCoderQC
Thanks for your instant reply and tutorials!
Did you make these just for my question or you had already done this before?
Anyway that’s so nice of you!
Looks like I should try to use SendEvent function to trigger events, the way I handle the variables with SetValue function is just like yours, I’m not sure why result varies, if you like, please check my blender file, might set a example for people who are new like me to make a little game.
I’m trying to make a little game to showcase the power of Armory, it can do a lot of tricks much better than old day BGE, and indeed I’v done something I couldn’t have done before by Armory, it’s really handy and powerful!
I can upload HTML5 files to school’s sever to showcase before, but the academic sever policy become strict these days from my country, I’m wondering can ordinary one register a GitHub space ,publish and run HTML5 file on there? It would be great if it does!

Thanks again, I’m going to try again, it’s getting close to what I want!

Welcome! :grinning:

I did this after your post. It also helped me eliminate the possibility of existing bugs.

Seems like you are using a bit older Armory. I suggest you first upgrade to the latest version. Also, there were a lot of textures missing in the blend file, so couldn’t run it. Please enable the External Data >> Automatically pack into .blend file and then save and send.

Yes, you could create a free GitHub account and push examples as I did. A reference video of how to do it.

4 Likes

Kudos to your efforts! :star_struck:
Something I’d like to add that you may want to check GoTo function of NavMesh, it doesn’t seem to work in SDK 2021 version( win10 64bit+ blender 2.83 LTS),
and the LookAt logic node seems generate correct matrix that actually make object look at target, but when you go around the object in some angle the rotation would shift undesired axis make it upside down, I use old way separating X,Y and do Artan2 , flip Z to fix it.

I’m an Armory fan, I use SDK2101 :heart_eyes:

Thanks for your help, you’ll learn how a newbie like me can go wrong with things :sweat_smile:
packed blender file

In return, I should try to promote and introduce Armory to my people, hope that I’m qualified to, demo with HTML5 is at least I can do, people should now this amazing feature of Armory!

3 Likes

@olsen Hi again,

I just noticed that there are currently some serious bugs related to the rerouting node in Armory. I suggest that you remove all the re-routing nodes and connect them directly.


These ones

I will be opening an issue about it soon, if not already present.

4 Likes

Thanks to you, @QuantumCoderQC
After some debugging, there was something wrong with OnVolume trigger or my logic issue, it works well before, something messed up at unknown nod cause it fails, after using SendEvent triggered by Raycast to specified spawned objects, the Health variables start to pick up events and work fine with mouse event now.
Just it’s not actually hit by bullets but to act hitting reaction under aiming and mouse click, not ideally simulating hitting procedure, it somehow is limited by tricky PhysicContact(not quite understand it ) and Volume Trigger(works well before), before I finding out the correct way to use them, Raycast and SendEvents seems like a reliable way to achieve this.
Anyway I can destroy enemy robots by shooting them 5 times or so, it’s fun to make game by Armory!

2 Likes