Hey, i have a hud that is applied to my character and i want that if my characters health (float variable) is getting lower that a damage texture will set its oppacity depending on the float, and the lower your health the more visible it is (kinda like the cod blood splatters on your screen), But i have idea where to start, please help and. Thank you
asked Sep 05 '15 at 09:47 AM in Using UE4
You will need to create a widget, then find a nice big blood splatter image on google images and drag it into UE4 editor.
Add a image to your widget in the designer and set its anchors to the 4 corners and make sure its set to fill the entire screen. Now select your blood image for it.
Now set its opacity to 0.
Now in the event graph On eventBeginPlay do a cast to your character ie cast to MyCustomCharacter and then promote that cast varaible (the bottom blue pin right click on it) to a variable called MyCharacter_reference.
Then create a a varaible myHealth in your widget of type float. On eventTick() drag in your MyCharacter_reference variable with ctrl held down to make a getter, drag off its pin and get the health varible from your character and then set myHealth to that variable.
Now go back into the desgner and bind the image opacity to myHealth
Alternatively you can bind opacity to a function that takes MyCharacter_Reference -> get charactersHealth -> return pin that will be cleaner.
Let me know if that makes sense and works for you. Remember that values like opacity work from 0-1 so if your characterHealth varaible in your character BP is 0-100 you need to divide it by 100 first in the widget once you get it from the mycahracter_Reference variable. Also remember you want lower health to make the image more opaque so you probably want to set myHealth to characterHealth squareRt or something else math-like basically yo will need to figure out the best way to mathemtically set your image opacity from 0to0.8ish from 1to0 like an inversion. My math skills arnt good enough to know the answer. Maybe multiply it by -1 to get it inverted (negitive) and then add + 0.9 so health 0.9 = -0.9 + 0.9 = 0 opacity but 0.5 will be -0.5 + 0.9 = 0.4 opacity and 0.2 health will be -0.2 + 0.9 = 0.7 opacity etc.
Don't forget to accept an answer that best clears your question up or answers it so when the community finds your question in the future via search/google they know exactly what you did to fix it/get it going as well as keeping AnswerHub clean so that it gets removed from the "unanswered questions" category.
answered Sep 05 '15 at 06:01 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here