Loading...
112
Game
Hayami-Chan 3D
10 months 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

The animations are working!

#MadeWithUnity #GameDev #Hayamichan

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

Yes, I'm still alive!

AND I've finally fixed major bugs in the game. The new release should be out soon!

#GameDev #Hayamichan

Highrise Game Jam Reminder: In order to enter to win the Jam, your game must be created in Unity and submitted using the Highrise Studio Hub.

Learn all the deets about the jam at https://gamejolt.com/c/gamedev/highrisejam

The hide and seek event is wip, but comes along very nicely!

#MadeWithUnity #GameDev #Hayamichan

πŸ₯³ The Highrise Game Jam is Underway! πŸ₯³

Watch the video for tips on getting started building your first world in Highrise Studio. (Creating and submitting within Highrise Studio Hub is the only way to enter the jam!)

Learn more: https://gamejolt.com/c/gamedev/highrisejam

THE ENDINGS UPDATE IS FINALLY HERE!!

● 4 Endings

● Improved Hayami-Chan Ai

● Android Version

● Bug fixes

HAYAMI-CHAN 3D IS NOW OUT

How long will you survive when your waifu comes to life & starts hunting you down?

Log in with your Game Token & compete for the highest score!

πŸ₯³The Highrise Game Jam has begun! πŸ₯³

The Highrise Game Jam is where creators come together to craft immersive 3D worlds using Highrise Studio! There are cash prizes! πŸ’ΈπŸ’ΈπŸ’Έ

Learn the deets here: https://gamejolt.com/c/gamedev/highrisejam

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