Forum rules - please read before posting.

Simple Health

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! 
«1

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...

  • You're welcome, @Neji!

    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.
  • ChrisIceBoxDeckard_89 , Sorry for the late reply I've been having exams.
    So, I tried following your method, but I couldn't understand much. It was difficult to follow up. I Kinda know somethings about Adventure creator, but I'm not familiar with the variables. How can I link the global variable which I named "Health" to unity UI first so I can make the Health system.. and then OnTriggerEnter lets say I lose 10% of health.. I will show you my progress so far..
    -
    image


    image
  • edited May 2017
    You can tie a float global variable to a slider component through the AC menu manager. Set the "Slider Affects" field to "Float variable", then select your float global variable from the list. 

    Now, you are using the Check actions wrong. You usually check the contents of a variable first, to decide if you want to do something or another. A Check action will give you two paths (see that it gives you two connections instead of just one): A success, and a failure (which will depend on the conditions you selected). That way you can run actions both if the condition was met or not.

    But, lets back up a little. The first thing you have to understand about variables, is that you use them so that your game can "remember" information. They can be bool (true or false), numbers (int,float) or text (string). The other important thing to remember is that they are not automatic, you have to Set their value yourself (I mention this, because I find some beginners expect them to be automatically set for some reason).

    Imagine you have a LeverWasPulled bool variable (which take true/false values). If the Player uses the hotspot for your Lever, then, in the actionlist in that hotspot, you use a Variable:Set action to change the value of LeverWasPulled. Then, in a hotspot for a Panel or a Door you can use a Variable:Check to see the current value of LeverWasPulled: If it's currently true, you run the open animation for the door, if it was false you can just play an error sound or whatever you want. 

    In the same Lever example, in the Lever's hotspot, you could first lay out a Variable:Check to verify if the value is currently true. If it is, you can use a Variable:Set to set it to false, if it's not you can do the same to set it to true. This way you get a simple on off switch.

    Next, you can chain Check actions.

    In the HP case you show above, let's imagine you want to remove HP, you'll want to run a Variable:Check first to check if the current value is equal to 0. Now, you get two paths: 
    1. If the result is true, then the HP is already 0 and you don't do anything in this case (you don't want negative HP do you?). 
    2. if it's not 0, then you can use Variable:Set with a -10 value (AC understands some arithmetic operations, so it will do the subtraction if you give it a negative number). In this same path, you'll likely want to do another Variable:Check next, checking if the variable is now negative. If it is, then set it to 0 (same as above, you don't want negative HP, right?) . Here too, you can, oh, kill the player, Lol.

    The process will be almost the same to add points, except you'll be checking for the maximum the variable can posses, which in your case will be 100 (if you don't do the checks, you'll end up exceeding the max...).
  • edited May 2017
    Actually, having a Variable: Set Action before your Variable: Check should be fine *provided that* you always check the value after changing it - hence my previous comment about moving it to a single asset file that you can call upon when needed.

    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:

    image

    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.
  • edited May 2017
    To clarify, I meant he was using the Check action wrong because he wasn't actually doing anything with it, lol. I just edited the post too much I guess (got lost in the edit). But yeah, the check can be place either way, I just prefer to use checks before to avoid unnecessary operations in some cases (it's a habit from my own way of scripting).
  • edited May 2017
    Guys, you are genius! Thank you so much for the help, it worked like a charm!

    I managed to connect the health variable with the triggers and all, I now even have the abilities to do a lot of things with the variables once I understood how it worked. However, there is a small problem, which I can't figure out how to fix, its probably a bug or something. I have a UI slider  and I linked it with AC menu, and everything is working fine, except when I change the min value and the max value of the slider, because I don't want it to be from 0 to 100, I want it to be from 50 to 200.  (the min is 50, and the max is 200), but when I do that it doesn't work. here is some pictures. 


    image

    image


    image

    and this is how the results show : 


    image


    when I place the min to 0 and the max to 1, it works perfectly fine, but not when I change them to whatever I want, it just shows like in the last picture, no value.. I'm not sure if this is a bug or unity Ui problem? what do think guys ? 
  • 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.

  • edited May 2017
    What's the value reported by the variable? You can see this in the Variables manager at runtime. I actually had a very similar issue just recently. Basically any AC slider set to have a min and max different than the defaults would get stuck at 1f (UGUI's slider component's settings just get overridden, and you can't change the value even if it's set to be changed by the user and you drag it manually- handle just jitters and remains at 1f). But due to lack of time, we just changed the way we were manipulating the variable. 

    Anyway, what Unity and AC version are you using? The latest AC version reports fixing an issue with sliders(though it mentions AC UI), maybe you should upgrade to the latest AC and try again (I will when I can too, but will need to try it with a backup of the project first, probably this weekend).
  • I second @Deckards_89's confusion about what's wrong with the image posted.  The slider will still appear fully "empty" and fully "full" depending on the value - it's just that "empty" will mean 50, not 0.

    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.
  • edited May 2017
    Well, in my case the min was 1 and the max was 10 (at first), but it was stuck at 1f no matter what (if you tried to increase it, you'd see the handle wobble for a moment, like struggling, lol). I did try setting it 0 min to 1 max but it gave me the same behaviour. It did feel like a script was trying to set the variable constantly, which might be possible, since we are talking about a project which was ported from PC to VR, so lots of unused scripts in the project, and lots of global vars which were deleted and other new created, making it possible the var id was already in use by some script. That's why I never reported the error, cause I couldn't verify if it wasn't just a script in the project which was actually causing the issue (didn't really test further cause my teammate decided we didn't really need that option anyways - and well, he is the only one who can test the game, so I agreed, lol).
  • I have the latest version of AC I believe, 
    and Unity version: 5.6
    -
    I know the images are causing confusing, but the thing is, no matter how much I change the min value and the max value it always appears empty like that in the last image, just empty slider.. but when its set to 0 - 1, from the slider, it will appear full which what I want, except I don't want it to be 
    0 - 1. If you ask me why does it matter ? because I'm trying to make a style more of a heart rate health system, when the normal heart rate starts at 50, but when I get hit or something The heart rate increases to 100 and eventually to 200 and the player dies. Well with your help I managed to do all that except I can't get the slider value to work with my logic.. it just won't accept anything except  0 as min value and 1 as max value.. I don't know If i should change my method and find something else like using the texts instead, but AC only works with the slider, right? So I'm not sure what I should do.. 
  • Again, please set your Menu's Source back to Adventure Creator and confirm you get the same behaviour without using Unity UI.  At the moment, I'm confused about the actual issue itself - do you mean the value itself is being mispresented? i.e. when the min/max is 50/200, and the variable is 200, is the slider fully empty?

    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).
  • Okay, so I am trying to follow this post in order to make a health bar myself.

    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
  • Does your game feature an opening Cutscene that blocks gameplay when the scene begins?  Or does the default "Menu" button in the lower-left (the "InGame" menu) show while your Slider menu doesn't?
  • edited May 2018
    Hmmmmm. So I checked my scene, and didn't see a cut scene. Or anything like a cut scene. [I thought maybe I created one by accident]

    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.

  • edited July 2019

    I conclude that a tutorial that shows how to "connect" AC to Unity's UI is needed

    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.

    Does AC offer a "game loop" a delta time if you will, so that a bar changes by every passing moment?

    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:

    GVar myStaminaVariable = GlobalVariables.GetVariable (2);
    myStaminaVariable.FloatValue -= 0.01f;
    

    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.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.