Billiard implementation

Hello!
I am trying to make turn based game similar to billiard using UNITY and PUN..
I would like to transfer initial strike only and then run physics on both machines. I already have a little prototype.

I disabled Physics2D.autoSimulation and I trigger shot using RPC with initial force. Then I run simulation using Physics2D.Simulate with constant 0.04f step on both machines. I only take shots once every Rigidbody2D is sleeping.

The thing is that in MOST cases everything works fine. Unfortunately for whatever reason from time to time things go completely out of sync.

I am testing Mac vs Android which may be the cause (different platforms), but I suspect it could go wrong even within Android platform itself.

I also tried to transmit transform positions and rotations but results are a little bit too jerky for my liking.

Any suggestions? Is my approach even possible?

Best regards!

Comments

  • Hi @ghua,

    this is an interesting approach. I have taken a quick look at Unity's Scripting API which provides a few sentences about it:

    To achieve deterministic physics results, you should pass a fixed step value to Physics.Simulate every time you call it. Usually, step should be a small positive number. Using step values greater than 0.03 is likely to produce inaccurate results.


    It maybe is helpful to lower the step in your project and see if this gives you the result you want to achieve. Of course you already might get different results on different machines, which can lead to certain problems.

    It would be interesting to know, if you can get it work properly. :)
  • S_OliverS_Oliver ✭✭
    Different approach would be to write a simple "physics" function wich only calcualte what you need
    https://docs.unity3d.com/ScriptReference/Vector3.Reflect.html

    https://docs.unity3d.com/ScriptReference/Vector2.Reflect.html

    Im using Vector.Reflect to achieve a physic like behaviour without physics and it is pretty accurate on network.
Sign In or Register to comment.