0

In my board game, the points are given by throwing 7 sea-shells cowry shell. These shells are dropped onto a sphere in Unity so they get rolled over randomly to different places. Once the rigidbody.isSleeping() returns true, I do a Raycast(from the belly side downwards) to figure out the orientation of the shell. If it is NOT a hit we know the shells belly is turned upside which means a point.

All is good and very realistic when in single player mode. Reason is I just activate the gravity of the shells and they dropped on to sphere, gets rolled randomly and when stopped i get the marks as stated above.

Now the problem is I am making the game multiplayer. In this case, I sent the randomly generated marks from the server and client will have to animate the shells to represent the marks. For example, if server send 3, out of 7 shells, 3 should have it's belly turned upside.

Trying to do this has been a major problem for me. I tried to transform.Rotate() when the velocity is reduced but it was not very reliable and sometimes acts crazy. Rotating afterrigidbody.isSleeping() works but very unrealistic.

I know I am trying to defy physics here, but there may be some ways to achieve what I want with minimum artificial effect.

I actually need some ideas.


Update - 1

After infor I receive below, I did found some information here, some advanced stuff here. Since the latter link had some advanced stuff, I wanted to start small. So I followed the first link and did below test.

I recorded the position, rotation & velocity of the sea shell with autosimulation enabled and logged them to a file. Then i used the Physics.Simulate() for the same scenario and logged the same.

Comparing the two tells me that data in both cases are kind of similar. So seems like for my requirements I need to simulate the sea-shell drop and then apply that sequence to the actual object.

Now my problem is how can I apply the results of physics.simulate() results (position, rotation, velocity etc..) to the actual sea-shell so the animation can be seen. If I set the positions to my gameobject within the simulation loop nothing happens.

    public void Simulate()
{


    rbdy = GetComponent<Rigidbody>();
    rbdy.AddForce(new Vector3(0f, 0f, 10f));
    rbdy.useGravity = true;
    rbdy.mass = 1f;

    //Simulate where it will be in 5 seconds
    int i = 0;

    while (simulateTime >= Time.fixedDeltaTime)
    {
        simulateTime -= Time.fixedDeltaTime;

        Debug.Log($"position: {rbdy.position.ToString()} rotation: {rbdy.rotation.ToString()} Velocity {rbdy.velocity.magnitude}");

        gameObject.transform.position = rbdy.position;

        Physics.Simulate(Time.fixedDeltaTime);
    }
}

So, how can I get this simulated data applied to actual gameobject in the scene?

user2058413
  • 691
  • 3
  • 10
  • 28

1 Answers1

1
  1. Assume Physics are deterministic, just set the velocity and position and let it simulate on each client. Output should be the same. If the output differs slighly, you could adjust it and it may be only barely noticable.

  2. Physics.simulate may be interesting to read, even if it's kind of the opposite of what you want.

  3. You can throw in the client, record the steps in realtime or using physics.simulate (see point 2) and transmit the animation data as binary - then use it in the other clients to play the animation.

KYL3R
  • 3,877
  • 1
  • 12
  • 26
  • I will read more about it. However what I need is at the end of the drop of shells it may bounce, roll, collide etc..etc.. and end up with a rotation with 90, 180, 180 (as displayed in unity editor transform). – user2058413 Dec 06 '18 at 13:22