- Home /
Question by
TheUninvited · Apr 29, 2020 at 03:25 PM ·
unity 5multiplayer-networking
Multiplayer ball not syncing properly using mirror.
Here is what is happening: https://youtu.be/hplh3X50xSY
public class Ball : NetworkBehaviour
{
private Vector3 lastFrameVelocity;
[SerializeField]
[Tooltip("Just for debugging, adds some velocity during OnEnable")]
private Vector3 initialVelocity;
[SerializeField]
private float minVelocity = 10f;
private Rigidbody rb;
private void Awake()
{
rb = GetComponent<Rigidbody>();
}
public override void OnStartServer()
{
base.OnStartServer();
}
void Update()
{
lastFrameVelocity = rb.velocity;
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Player"))
{
Bounce(collision.contacts[0].normal);
}
}
private void Bounce(Vector3 collisionNormal)
{
var speed = lastFrameVelocity.magnitude;
var direction = Vector3.Reflect(lastFrameVelocity.normalized, collisionNormal);
rb.velocity = direction * Mathf.Max(speed, minVelocity);
Debug.Log("Out Direction: " + direction);
}
}
Comment
Your answer
Follow this Question
Related Questions
Can I see how many bytes are being sent by a particular SyncVar variable? 1 Answer
How to set namespace in packet of socketIO using unity3d 1 Answer
RPC and Command Calls OR Network messages for syncing variables across Server and Client? 0 Answers
Unet Multiplayer, Have same layout for each player in 2D game. 0 Answers