public void HandleCollision(GameObject collider, ICollisionPart part) { if (!isServer) { return; } Ball ball = collider.GetComponent <Ball>(); if (ball == null) { Debug.LogError("Нет компонента Ball"); return; } // просто рикошетим Vector3 ballDirection = ball.MoveDirection; Vector3 oppositeDirection = new Vector3(-ballDirection.x, -ballDirection.y, 0f); float signedAngle = Vector3.SignedAngle(oppositeDirection, part.Normal, new Vector3(0f, 0f, 1f)); Quaternion rotateQuaternion = Quaternion.Euler(0f, 0f, signedAngle * 2f); Vector3 reboundDirection = rotateQuaternion * oppositeDirection; ball.MoveDirection = reboundDirection; Edge wall = part as Edge; if (wall != null) { wall.ForbidColliding(0.2f); } }
public void HandleCollision(GameObject collider, ICollisionPart part) { if (!isServer) { return; } Ball ball = collider.GetComponent <Ball>(); if (ball == null) { Debug.LogError("Нет компонента Ball"); return; } Vector3 ballDirection = ball.MoveDirection; Vector3 oppositeDirection = new Vector3(-ballDirection.x, -ballDirection.y, 0f); float signedAngle = Vector3.SignedAngle(oppositeDirection, part.Normal, new Vector3(0f, 0f, 1f)); Quaternion rotateQuaternion = Quaternion.Euler(0f, 0f, signedAngle * 2f); Vector3 reboundDirection = rotateQuaternion * oppositeDirection; if (currentSpeed > 0.01f || currentSpeed < -0.01f) { Debug.Log(player.PlayerIndex); Quaternion speedQuaternion = Quaternion.Euler(0f, 0f, player.PlayerIndex == 0 ? currentSpeed * 4f : -currentSpeed * 4f); reboundDirection = speedQuaternion * reboundDirection; } ball.MoveDirection = reboundDirection; for (int i = 0; i < edges.Length; i++) { edges[i].ForbidColliding(0.2f); } }