I’m a new GD who trying to make a turn based rpg.
I’m try to make a random encounter system.
Every area has a monobehaviour only keeps scriptableobject that saves areaInfo. Every area has an int difficulty and secToRoll variable. When player enters an area waits for ‘secToWait’ time then takes a Random number between 1-100 and checs if its below to difficulty of that area. If it is then start to CombatStat, if it’s not then wait another ‘secToWait’ time and take another Random number.
So i tried some diffrent things and i faild. Number 1 problem that i chouldn’t manage to solve is:
When player enters the area waits “SecToWait” time and takes a random number but after that its keep taking random numbers every frame until if(randomNumber<=difficulty) statement is true.
I don’t know i write right and understandable(Eng not my primary language…abviously!) But i really need some help here Thnks.
It would help if you showed your actual code, but it seems like you messed the conditions up.
Algorithmically this should look as follows:
Variables: secBetweenRolls = seconds between rolls, curTime = now / the tickcount, lastRollTime = time of last roll
Behavior: You want to check every frame if curTime is at least as high as (secBetweenRolls + lastRollTime). If not, do nothing. If so, set lastRollTime = curTime, roll a random number and do your test for whether it’s under the difficulty.
That’s basically it. Since after each check you set lastRollTime to the current time, you always wait secBetweenRolls seconds before the condition turns true again. If you start a battle, at the end of it you should set lastRollTime to now aswell tho, since otherwise you may directly roll for the next battle which may be annoying.