Loading...
114
Game
Hayami-Chan 3D
2 years ago

Working on the hunting AI. I'm using the nodes in the apartment and chances to let #Hayamichan choose a new destination...

Useful c# script is in the article!

#MadeWithUnity #GameDev


With this script you can draw an index based on chances. It's really useful!

PropabilityPool.cs

		
			using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace DonutStudio.Utilities.Propability
{
    /// <summary>
    /// Class to draw a random element from a pool of rates.
    /// </summary>
    public class PropabilityPool
    {
        float[] rates;
        float total;

        /// <summary>
        /// Create an object of the PropabilityPool class with the rates.
        /// </summary>
        /// <param name="_rates">The rates of the single elements.</param>
        public PropabilityPool(float[] _rates)
        {
            rates = _rates;

            UpdateTotal();
        }

        /// <summary>
        /// Draw a random element for a pool of rates. The higher the rate the higher the chance.
        /// </summary>
        /// <returns></returns>
        public int DrawElement()
        {
            float r = Random.Range(0f, total);
            float accumulatedProbability = 0f;

            for (int i = 0; i < rates.Length; i++)
            {
                accumulatedProbability += rates[i];
                if (r <= accumulatedProbability)
                    return i;
            }
            return 0;
        }

        /// <summary>
        /// Change the value of a rate.
        /// </summary>
        /// <param name="index">The index of the rate.</param>
        /// <param name="newRate">The new value of the rate.</param>
        public void ChangeRate(int index, float newRate)
        {
            if (index < 0 && index < rates.Length)
                return;
            rates[index] = newRate;
            UpdateTotal();
        }
        /// <summary>
        /// Change all the rates.
        /// </summary>
        /// <param name="newRates">The rates.</param>
        public void ChangeRates(float[] newRates)
        {
            rates = newRates;
            UpdateTotal();
        }
    
        /// <summary>
        /// Update the total value of all rates
        /// </summary>
        void UpdateTotal()
        {
            total = 0;
            foreach (float f in rates)
                total += f;
        }
    }
}
		
	


8 comments

Loading...

Next up

Working on the endings. You'll have to find them out yourself. The build (and mobile version) will be uploaded asap... show some patience xD

#MadeWithUnity #GameDev #Hayamichan

Damn,

if this ain't spectacular, I don't know what is. The game has six different languages to select.

Special thanks to @FriendlyFrenchyFoxOff for translating. Be sure to check out his account. He rocks!

#MadeWithUnity #GameDev #Hayamichan

Working hard on the game, so you can play it (hopefully this month).

I think it might not be that scary, but good enough for my first #Horror game

#MadeWithUnity #GameDev #Hayamichan

Congrats to Dotemu for launching their new game Absolum! Hades + Streets of Rage = Yes, oh and it's 10% off for launch'

Check out the game: https://bit.ly/absolum

coming soon

@BeyondThePixels is a Jolter to Watch and a game developer re-inventing 90s retro cool for todays gaming community!

Check out their game Astro Burn: https://gamejolt.com/games/Astroburn/1023196

Follow them before the quest ends on October 21 and you'll get Coins!

Can you guess what this could be?

Say no more!

I've finally added mobile controls. It took a ton of work to redo the input system, but now I can just export the game for android and everything should work

🚨 Radio Hoomanz🚨 Ep3 – Announcement 📢

âž” Wishlist Hoomanz on Steam & join our Discord! Link in bio!

Play as Shoo, guardian of Planet Erf with a hidden dual nature, in a cozy stealth-adventure to scare away all the invading Hoomanz!

#hoomanz #radiohoomanz

The hide and seek event seems to work fine. Now I have to implement the hunt event when #Hayamichan sees you...

#MadeWithUnity #GameDev #Horro