diff --git a/Assets/Mirror/Examples/Pong/Scripts/Ball.cs b/Assets/Mirror/Examples/Pong/Scripts/Ball.cs index a4fd896f9..b06bc7dda 100644 --- a/Assets/Mirror/Examples/Pong/Scripts/Ball.cs +++ b/Assets/Mirror/Examples/Pong/Scripts/Ball.cs @@ -10,9 +10,24 @@ public override void OnStartServer() { // only simulate ball physics on server GetComponent().simulated = true; + } - // Initial Velocity - GetComponent().velocity = Vector2.right * speed; + [ServerCallback] + void Update() + { + Rigidbody2D rb = GetComponent(); + + // if less than two players then reset ball + if (NetworkManager.singleton.numPlayers < 2) + { + rb.velocity = Vector2.zero; + transform.position = Vector2.zero; + } + // if two players joined, then enable velocity if not done yet + else if (NetworkManager.singleton.numPlayers == 2 && rb.velocity == Vector2.zero) + { + rb.velocity = Vector2.right * speed; + } } float HitFactor(Vector2 ballPos, Vector2 racketPos, float racketHeight)