Hunger and Thirst

plutonmania

Member
Good morning,
I am now trying to replicate the UCC health system for UIS with consumable items.

I have wandered a bit on the forum and the documentation, but I would like to have a little more explanation, if possible.
(I know that I still have a LOT of questions to ask you, sorry if this can be tiring in the long run for you, but I want to be successful in everything I do.
I duplicated the 'Health' category to create 'Food' and 'Thirst'.

1.PNG

I created 2 definitions: 'Can_food' and 'Flask'.
I duplicated the 'Heatlh' UI twice to create my 2 Hunger and Thirst bars.

2.PNG

On my playable character, I added in 'Character Attribute Manager' my two new attributes. I put the 2 'decrease'.

3.PNG

I launch the 'Play' mode

- My 2 UI bars are there.
- It decreases well (a little too quickly but I think I know where to adjust)
- Once reached '0', How do you proceed so that 'Health UI' decreases in turn tends that the bar 'Food UI' or 'Thirst UI' are not filled?
- How to make the consumed item fill the desired UI bar? an action type in the inventory saying 'consume' or 'use' as for the definition 'heath pack' ?
- How to have an animation to have an animation of the character who consumes the product ?
--- >create an 'item abilitie' in ultimate character locomotion and how to link it to my action ?


please tell me not to create a script (haha) o_O

Thank you for your patience !
 
Once reached '0', How do you proceed so that 'Health UI' decreases in turn tends that the bar 'Food UI' or 'Thirst UI' are not filled?
There's no automatic way to do this. @Justin perhaps you have a beter idea?
How to make the consumed item fill the desired UI bar? an action type in the inventory saying 'consume' or 'use' as for the definition 'heath pack' ?
Assuming you do this with an item action by using the item from the Inventory UI. You would use an Inventory Item Action called "Character Modify Attribute(s) Item Action". You can seperate the action by category if you can't get it to work for both in one action at the same time

I you want an UCC item that can be equipped then you could go another direction using an Usable CharacterItemAction. Check out the FlashLight item in the Character controller demo scene. This is a bit more complex since there isn't a way to automatically remove an character item after it has been used apart from throwable item like grenades.

How to have an animation to have an animation of the character who consumes the product ?
Assuming you are going the ItemAction route, you can combine multiple ItemActions in one action by using a "MultiItemAction" item action. unfortunatly we do not have a generic Inventory Item action for playing an animation. The way we did the Sword attack or the bomb throw in the Inventory system demo is by adding a script on the Weapon itself.

We could add an Inventory ItemAction to play an animation on its user if you think it can be useful. it's very easy to do.

If you are going the UCC equipment CharacterItemAction route. Then the animation can be set throw the Character animation system with the item id.

--- >create an 'item abilitie' in ultimate character locomotion and how to link it to my action ?
We don't have a Inventory Item Action that can use a Character ability. But I think this is something we could add fairly easily if you want. We already have an Invnetory Item Action to equip and use an character item. So it should be fairly easy to do.


TLDR: There are many ways you can implement this. We can update the code to add in some of the functionality if it's something that can be useful to most people.
The first step is for you to choose whether the item should be equippable or not because that will affect which systems you can use. And how it will work in practice.
 
Hello,
I followed your advice and was finally able to create consumable items for hunger and thirst. and it's work fine.
-----------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------


FOOD.PNGINVENTORY GRID.PNGTHIRST.PNG

-----------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------


I tried to implement it in the 'health.cs' script, which is used for 'characterhealth.cs'. I added the attributes 'food' and 'thirst' to it.
So, I modified the 'health.cs' script and the 'HealthInspector.cs' script.
I simply duplicated the logic from the 'shield'.
I know there may be inconsistencies regarding hunger and thirst compared to the shield code.

Firstly, I'm happy that I managed to add my two attributes to the 'characterhealth' component.
4.PNG

I'm sharing the scripts , "health.cs and "healthinspector.cs" modified [lien Mega] for better understanding.
I'll proceed step by step.

How can I add code that checks if both 'food' and 'health' are 0f, and then 'health' takes 10f damage every frame until death?
But if either 'food' or 'health' increases, the damage to 'health' should stop.

Here are my experiments:
C#:
private void Update()
{
    if (m_FoodAttribute != null && m_ThirstAttribute != null)
    {
        if (m_FoodAttribute.Value <= m_FoodAttribute.MinValue && m_ThirstAttribute.Value <= m_ThirstAttribute.MinValue)
        {
            // Both food and thirst attributes are at or below minimum value, start reducing health.
            Damage(10f, m_Transform.position, Vector3.zero, 0f);
        }
        else
        {
            // Food or thirst attribute has increased, stop the damage.
            CancelScheduledDamage();
        }
    }

}

private void CancelScheduledDamage()
{
    // Annuler les dégâts programmés en arrêtant une coroutine.
    StopCoroutine("ScheduledDamageCoroutine");
}

private IEnumerator ScheduledDamageCoroutine()
{
    while (true)
    {
        Damage(10f, m_Transform.position, Vector3.zero, 0f);
        yield return null;
    }
}

But not work ! i have delete this code.

And for the animation of the item consume with the object in your hands "a bit like grenade" that you said. I would see a little later after succeeding this.

I think @Justin can also answer it.
 
I would not modify health for this. I would make abilities. Hunger and Thirst, or just one ability "Survival". That ability would be always running, and handling the attributes itself. I would then decrease health if the attribute values are 0 from within the ability. Hope this helps you achieve your goal :) Rather than running a while loop you can schedule an event for ten seconds. Or use a simple timer within update. float nextCheckTime = 0; then in Update() if(Time.time > nextCheckTime){//do stuff ... nextCheckTime = Time.time + 10f;}
 
Thanks for your help. You mean to make an ability item ?
I don't think I can do that at least write code. Already I was using Chatgpt.
I was already happy to have been able to make an object consume and goes up the bar of thirst or hunger :)

After if Sangemdoko or Justin adapted the code for that (I think it would be more for UIS than UCC.)
It would help me a lot and maybe even the other members of the community who would like this.

- Make an item that is consumed with an animation when it eats or drinks, and an item that appears in the hand of the player.
- And when the bars of hunger or thirst are 0. Health takes domage until the death of the player or so until a object consuming stop that.
 
Top