Hi
I have 2 scene variables for hp Head and “Variable(Enemy.HP.HeadMax)” and “Variable(Enemy.HP.Head)” .
Damage is subtracted from Variable(Enemy.HP.Head) and I use Variable(Enemy.HP.HeadMax) to know when to stop regenerating .
I want text object Head to dynamically change color from green to orange to red and when Variable(Enemy.HP.Head) = 0 to be black.
The way it’s currently set-up:
If scene variable Enemy.HP.Head is less then 60% of max hp, the text object “EnemyHead” color changes to orange.
if scene variable Enemy.HP.Head is less then 30% of max hp, the text object “EnemyHead” color changes to Red.
If scene variable Enemy.HP.Head = 0, the text object “EnemyHead” color changes to Black.
So what happens at the moment? You describe what you’d like it to do, but not what symptoms it currently exhibits.
Also, your events in the screen snippet don’t show any of the variables you mention in your post. I suggest you change your events to match your post, or screenshot the events that do.
If scene variable Enemy.HP.Head is less then 60% of max hp, the text object “EnemyHead” color changes to orange.
if scene variable Enemy.HP.Head is less then 30% of max hp, the text object “EnemyHead” color changes to Red.
If scene variable Enemy.HP.Head = 0, the text object “EnemyHead” color changes to Black.
Ok. Let see if I got this right - you want the colour to initially be green. As the Head value decreases, you want the colour to slowly change too.
At the moment, you’ve got thresholds (60%, 30% and 0%), at which the colour changes. Abruptly. You’ve not told it to gradually merge from one to the other.
There are a few ways to achieve this. I’ll give you two:
And change the ‘- 60’ and ‘- 30’ to ‘- 0.6’ and ‘-0.3’. The 3rd lerp parameter should be between 0 & 1.0
In the last screenshot, you’ve got more closing parenthesis than opening ones. You need an opening bracket before the Variable keyword.
Colour is set as a string, made up of 3 components red, green & blue, which are values that range from 0 to 255. We’re trying to slide from one colour to the next by changing these components using lerp. I suggest you look up lerp and how it works to understand what we’re doing to each component.
The calculation involving headPercent is to get the range (60%-100%, 30%-60% and 0%-30%) into a value from 0 to 1. So, for example, a headPercent of 80% is halfway in the first range (60%-100%), so should end up as 0.5 (halfway) as the 3rd lerp parameter. A headPercent of 50% is 2/3 of the way from 30% TO 60%, so it should end up around 0.66.
Is this correct?
ToString(lerp(0,255,(Variable(Enemy.HP.HeadPercen)-0.6)*2.5))+";"+ToString(lerp(255,160,(Variable(Enemy.HP.HeadPercen)-0.6)*2.5))+";0;0"
Not quite - you have one too many zeros at the end. And check the variable name (it’s missing a ‘t’)
Another (and less complex/convoluted) method you could try is to break the ranges into lots of 10%, and set the colours accordingly. It won’t give a super smooth transition, but will provide a reasonable change.
What I mean by that is calculate headPercent, and have 10 events with the conditions:
if (headPercent >= 0.9), set colour green
if (headPercent >= 0.8 and headPercent < 0.9), set colour slightly orange green
if (headPercent >= 0.7 and headPercent < 0.8), set colour slightly green orange
if (headPercent >= 0.6 and headPercent < 0.7), set colour orange
if (headPercent >= 0.5 and headPercent < 0.6), set colour slightly red orange