Random Behavior in Deterministic Replay Systems

So I mentioned the two types of Replay System to a friend at work. Like me, he didn’t know this was how game replays worked behind the scenes and was interested, particularly with Deterministic Replay Systems. But I didn’t expect him to come back with this question that I couldn’t answer.

How do random NPC behaviors work in a Deterministic Replay System?

For example, if there are two characters that the NPC could attack; A and B. During the game, the NPC attacks A, but it is programmed to select its target at random. During Deterministic playback, if it were truly random, the NPC might not attack character A during the replay. Is this situation possible?

Mark, how are you?

Usually replay systems are made within different classes just as Ben showed us, and the actual game structure will be responsible for running the game using these classes instead of the actual player input or random generators. Make it saving the actual GameObjects transform won’t always work, but it was enough to show the class example.

Regarding your question, once the NPC generates the attack and rolls a random number, the system should be able to save the target within an array and then play it back, something like this:

void ChooseTarget()
{
GameObject target;
float randomTargetNumber = Random.Range(0f,1f);
if (randomTargetNumber >= 0,5f) 
{
target = A;
}
else
{
target = B;
}
NPCReplaySystem.SaveAttack(this, time.time, target) 
Attack(target);
}

And then it should use the information saved to the NPCReplaySystem.SaveAttack method to playback, information about who attacked who and when.

1 Like

Privacy & Terms