- Home /
Question by
TheEnigmaticOrator · Jun 26, 2020 at 07:15 PM ·
attributerandomization
Random outcome affected by player attributes
I'm trying to come up with a system where the player can do a "choice" and that choice has a randomized outcome which is either positive or negative. For the system to be complete I need to randomize the outcome whilst having a player attribute like "intelligence" affect the positive outcomes probability. After this i will return a simple bool value to indicate which outcome was randomized.
Example of my code:
attributeX = 10;
attributeY= -10;
attributeZ= 100;
private bool CalculateProbabilities(Choice choice)
{
float pos = choice.basePositiveProbability + attributeX;//attributeX just as an example could be attributeY or attributeZ too
float neg = choice.baseNegativeProbability;
//Randomize an outcome based on the probabilites.
}
Does anyone have any knowledge on how a calculation like this could/should be coded?
Comment
Best Answer
Answer by unity_ek98vnTRplGj8Q · Jun 26, 2020 at 08:03 PM
If you are just looking for a basic system that adds the attribute probability to the base probability then you just need to do something like this
private bool CalculateProbabilities (Choice choice) {
float pos = choice.basePositiveProbability + attributeX;
return pos >= Random.Range(0, 100);
}