# What does determinism mean in Unity.Physics

Discussion in 'Physics for ECS' started by BugsBuggy, Feb 3, 2020.

1. ### BugsBuggy

Joined:
Apr 24, 2014
Posts:
12
I need deterministic physics for a dice game. My understanding is that determinism means that if you put all dice in set locations and rotations and apply the same forces/velocity they will fall the same way every time! That is not true in my tests. I might be doing something wrong but most likely I just have the wrong idea of what determinism is.

2. ### steveeHavok

Joined:
Mar 19, 2019
Posts:
481
We did discover a determinism bug last week which we are in the middle of fixing for the next up coming release. That said, do you have any other systems in place that apply forces? Are the entity id changing at all? These sorts of things can also effect determinism.

3. ### BugsBuggy

Joined:
Apr 24, 2014
Posts:
12
I am pretty new to DOTS, so I might be screwing something up, I have 6 cube walls which are set to static. Then I have 5 Dynamic cubes for dice and only one system which listens for input and resets the dice and adds velocity.
Code (CSharp):
1. using Unity.Entities;
2. using Unity.Mathematics;
3. using UnityEngine;
4. using Unity.Physics;
5. using Unity.Transforms;
6.
7. public class InputSystem : ComponentSystem
8. {
9.     protected override void OnUpdate()
10.     {
11.         bool tPressed = Input.GetKeyDown(KeyCode.T);
12.
13.         this.Entities.ForEach((Entity en, ref PhysicsVelocity velocity, ref Translation position, ref Rotation rotation) =>
14.         {
15.             if (tPressed)
16.             {
17.                 int zeroBasedIndex = en.Index - 6;
18.                 position.Value = new float3(-3 + zeroBasedIndex * 1.1f, 0, 0);
19.                 rotation.Value = quaternion.Euler(0, 0, 0);
20.
21.                 Debug.Log("T Pressed!");
22.
23.                 if (zeroBasedIndex <= 1)
24.                 {
25.                     velocity.Linear = new float3(2f, 0f, 15.0f);
26.                 }
27.                 else if (zeroBasedIndex >= 3)
28.                 {
29.                     velocity.Linear = new float3(-2f, 0f, 15.0f);
30.                 }
31.                 else
32.                 {
33.                     velocity.Linear = new float3(0f, 0f, 15.0f);
34.                 }
35.             }
36.         });
37.     }
38. }
So are you saying that all things being right, what I am trying to do should work?