Hi everyone,
ChrisIceBox for being awesome and responsive! He helped solve some issues that Iv'e been having related to AC, so thanks to you man!
-
I wanna talk about health system in adventure creator. I've been searching and looking everywhere but I couldn't find a single topic about it. I'm having issues with it, and it also would be good for people to find a topic like that in here. So, what I want to discus is, how do we make a health system in AC? The only way I heard of is by making UI Canvas and somehow connect it to AC Menu. However, even If I did all that, how am I able to to lose health if for instant, I touched a trigger? and lets say I wanna pick an item that goes to my inventory, and I want to consume it to refill my health? I just want to know the very simple and basic way, so I can get up on my feet and start doing some work. I just don't know how or where to start. A few leads would be appreciate it folks!
Thanks in advance!
Comments
Well, you could easily define Health as a Global Variable, and a trigger set to OnEnter would have an action to decrease the amount, and also check if the amount reaches zero, in which case you'd want another action, like play a dying animation or whatever, then an Action to bring up the Load Game Menu (just from the top of my head, I may have missed something).
As for using inventory items directly on the player rather than an in-world hotspot, that's something I need to know as well...
An integer or float Global Variable would indeed be the way to do it. The Variable: Set Action can be used to increase/decrease values by a set amount, as well as to set specific values.
Follow this up with a Variable: Check Action to see if it's below zero, and show whatever "Game Over" sequence you want if so.
You should actually create a dedicated ActionList asset for anytime the player loses health, and make the Variable: Set value a parameter - this way you can call this same list each time, and just alter the amount that the health is deduced by. A tutorial on parameters can be found here.
As for using items on the Player, you can do this by adding a Hotspot onto the prefab as a child object. The default Box collider can be replaced with a Capsule collider if necessary. As this is a prefab, the Actions that run will need to live in asset files - so just change the Hotspot components Actions source field to Asset File and you should be fine.
Your Variable: Set Action is currently setting the Health value to 100 - because your Method is Set Value. Set it instead to Increase By Value, and then enter in -10 as the value beneath it (for 10% health drop). This will subtract ten from the variable's current value. You can then use the Variable: Check Action to determine if it is below zero or not. Try the following instead:
Also know that variables are covered in the 3D tutorial, which you should definitely watch if new to AC - even if working only in 2D, as many of the principles are applicable to both styles.
Hmm... I'm not too experienced with UI's at this stage, but it says on your slider script you have the value set to 50 - which is the minimum, so having the slider "bar" being empty looks correct. If you want it to be full, then surely it should be 200?
Apologies if I've misunderstood something here.
Whenever you have an issue with AC/UI, the first thing to do is switch back to an Adventure Creator-based Menu, so that we can see if this is an issue with AC, or an issue with Unity UI.
A slider set to its mininum value will always be fully empty, and set to its maximum will always be fully full - if you want to show a slider as "half-full", you'll have to leave its minimum as 0 but then prevent the value its representing from going below e.g. 50.
You can do this with a Variable: Check Action to check if its below 50 followed by a Variable: Set Action if this is the case.
One other thing to consider is leaving it as 0->1, but then use the Variable: Set Action to take that value and convert another variable to the one you actually display. This Action has a forumla method, and formula's except variable tokens in place of actual variable values, i.e.:
[var:2] * 150 + 50
will convert a value of 0->1 to 50->200 (where "2" is the ID number of the slider's variable).
However, my slider keeps disappearing when I push play? I am not sure why. Did I miss a step?
I made sure to make the menu show up "during game play" so that I can test it immediately.
Here is my slider info:
A screenshot of my slider info:
https://78.media.tumblr.com/fb53be70ca8339450e2ff9be9289909a/tumblr_p8l184XBMk1qhotijo1_1280.jpg
A screenshot of the slider in game. Nothing exciting, but this is what disappears when the game starts:
https://78.media.tumblr.com/7a5c21f880268653701cc88a0632b360/tumblr_p8l1bqlmcO1qhotijo1_1280.jpg
The "in game" menu also wasn't showing up. After a while I gave up and just made a new game wizard. The project I was working on was just a prototype anyway. So, not a whole lot was there.
Now everything works. Doesn't really solve my original problem, but oh well. Thank you!
EDIT: Okay, so I figured out the problem. I had the game "wait" every time it decreased the value in order to make the decreasing slower. However, I forgot to make the trigger "run in the background" so it kept pausing the game.
Figured someone else would run into this problem and wanted to share!
trying to understand what goes on in this thread I conclude that a tutorial that shows how to "connect" AC to Unity's UI is needed because it shouldn't be so difficult to just use a health bar which is something needed for almost all games. Also the menu metaphor is not that clear, maybe a node thing should replace the menu metaphor used for components in AC. I really don't know how hard are these things to make , so it is a suggestion.
Additional question. Does AC offer a "game loop" a delta time if you will, so that a bar changes by every passing moment? Like if you want to have a stamina bar that decreases as time passes over during a fight.
A text tutorial on linking AC with Unity UI can be found here. Video tutorials that cover this topic can also be found here, here and here.
AC is designed with traditional adventure games in mind, which is why health bars are not included in the default interface. However, an AC Slider element can be connected to a Unity UI Slider component in the same manner. If you are having trouble attempting this, please share screenshots so that specific help can be given.
You can create an ActionList that runs in the background, and uses a Variable: Set Action to reduce the variable's value, followed by an Engine: Wait Action to wait however long you need, and then loops back onto the first Action. See the Manual's "Background logic" chapter for more on this.
Know that you can also modify AC's variables through script. If you wanted to do so from a regular Update function, you can:
Where "2" is replaced with the ID number of the variable you wish to affect. See the "Variable scripting" chapter for more on manipulating AC variables through code.
@ChrisIceBox you are SO HELPFUL and your support is great! I will get back at you as soon as I try your help. If it will be a good point what I really want to have is at the bottom of the screen something that shows the current player (as I would like to be able to switch player) the current inventory item at hand (ie a flashlight) and three or more bars that show thing like body health, mental health and hunger. These bars i want to be changing as you play.