Probability Influence

Note: this guide is a work in progress and is based on the Monster Spawner Sample. Expect an update with the full guide in the coming days.


What is Probability Influence?

Simply put, the influence is a float between -1 and 1, with zero meaning there is no influence.

In RNGNeeds, you can define influence by implementing IProbabilityInfluenceProvider interface. An object or class implementing this interface can be assigned to any item in list, and will server as a provider of the value between -1 and 1, thus becoming an Influence Provider. In addition, values themselves can be influence providers. In this sample, the SpawnLocation MonoBehaviour is the provider and the logic and math of the value is defined by the player's distance.

Spawn Location Code

public class SpawnLocation : MonoBehaviour, IProbabilityInfluenceProvider
{
    // code not relevant for this guide was omitted
    
    public Transform playerLocation;
    public float DistanceToPlayer => Vector3.Distance(transform.position, playerLocation.position);
    
    public float ProbabilityInfluence => DistanceToPlayer.Remap(0f, 30f, 1f, -1f);
    public string InfluenceInfo => $"Distance to player: {DistanceToPlayer} = {ProbabilityInfluence}";
}

In this case, the distance to player is remapped - if the distance is zero, the influence provided will be 1, meaning the maximum positive influence on the probability. And if the distance reaches 30, influence will be -1, the maximum negative influence.

So how does this simple value actually alter the probability? Entering Influence Spread ...

What is Influence Spread?

Spread defines the limits on how much the influence adjusts the probability. Remember the sliders with handles? That's spread, and using the slider, you can define the amount the probability raises or drops for each item individually.