- Home /
Question by
mrawesome4212 · Nov 29, 2014 at 04:19 PM ·
networkingserverclientfailure
How can I sync rigid bodies over a network?
So I'm not the best at coding and i have to sync rigidbodies over a network or server. Here is the script I have:
using UnityEngine;
using System.Collections;
public class rubbleupdate : MonoBehaviour {
//vars\\
private Vector3 lastpos;
private Quaternion lastrot;
public bool isserver = true;
void Start () {
if (Network.peerType==NetworkPeerType.Server) {
networkView.RPC("updatemov",RPCMode.OthersBuffered,transform.position,transform.rotation);
} else
{
transform.rigidbody.isKinematic = true;
isserver = false;
}
}
void Update ()
{
if (isserver == true)
{
//update movement
if (Vector3.Distance(transform.position, lastpos) >= 0.1)
{
//update last pos
lastpos = transform.position;
networkView.RPC("updatemov", RPCMode.OthersBuffered, transform.position, transform.rotation);
}
if (Quaternion.Angle(transform.rotation, lastrot) >= 1)
{
lastrot = transform.rotation;
networkView.RPC("updatemov", RPCMode.OthersBuffered, transform.position, transform.rotation);
}
}
}
[RPC]
void updatemov (Vector3 newpos, Quaternion newrot)
{
transform.position = newpos;
transform.rotation = newrot;
}
}
What happens is the server side it works fine and on the player side everything is frozen and will not move.
Comment
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Why can't the client move a networked object ? 1 Answer
Connect to remote private IP 1 Answer
Connect to Server on different computer (local network) 0 Answers