- Home /
How to make add force/Physics consistent between editor and builds?
I have researched and looked at all other posts with no success. I am creating a network game where a dice roll is involved, I have the server generating random floats and then sending that information to the clients that then uses those numbers for the torque and add forces. The issue is that if the client is in the editor or have different quality settings the results come out different than they are supposed to. I have tried modifying the Fixed Timed Step. If anyone has any ideas please let me know.
Note: It does not even seem to be add force most of the time, it seems to just be physics itself is inconsistent between the qualities, I understand why but I do not know how to fix this.
Code: This is being called from a FixedUpdate function.
public void Roll(float y, float right, float up)
{
transform.localScale = startScale;
transform.rotation = startRotation;
rb.velocity = Vector3.zero;
rb.mass = 1;
rolling = true;
isMoving = true;
transform.position = startPos;
rb.AddForce(new Vector3(0, y, 0), ForceMode.Force);
rb.AddTorque(transform.right * right, ForceMode.Force);
rb.AddTorque(transform.up * up, ForceMode.Force);
}
Post some code examples of where you apply torque and forces.
@Reddoge Did u find the solution I have the same issue.
Did you find the solution??. If you have please let me Know I have the same issue.
Answer by ImpOfThePerverse · May 15, 2018 at 12:59 AM
The most reliable solution would probably be to record the dice rolls as animations, then play back the appropriate animation based on the output from a random number generator. I don't think the physics engine will ever be entirely deterministic to that degree, since it relies on precise timing and order of execution. There was something on the asset store that could record gameplay to animation files, but it looks like it's been taken down. It's pretty easy though to write a script that records transform data to a file at regular intervals (every 60th of a second or whatever), then another script to read the recorded transform data and apply it to your dice.