Having problems with multiplayer syncing
Hello everyone.
I've been trying to figure out this multiplayer syncing problem for a couple of weeks now and it seems that i can't get my head around it. In short:
Players sync correctly on stationary platforms.
Player position goes out of sync on moving platform.
You can rotate the hexagon by pressing left shift (hexagon rotates 60 degrees and is controlled by the animator). Currently it only rotates only once.
Here's the repository access
here's also small gif from the problem:
From the hosts view the client is shifting 60 degrees away and maintains it's absolute position even while both players are parented to the hexagon. Add comment
Relevant parts of the code:
Here's the controller that handle's input (isLocalPlayer) and sends command to rotate hexagon.
public class Controller : NetworkBehaviour
{
CharacterController characterController;
Transform parentHexagon;
RaycastHit hitInfo;
public float gravity = 21f;
public float terminalVelocity = 20f;
public float jumpSpeed = 12f;
float verticalVelocity { get; set; }
private Vector3 moveVector { get; set; }
public float yRotation = 0f;
public float rotationMultiplier = 1f;
[HideInInspector]
public float totalRotation = 1f;
public float speed = 0f;
float previousSpeed;
void Awake()
{
characterController = GetComponent<CharacterController>();
}
void Update()
{
FindCurrentPlatform ();
CmdHandleInput ();
}
// This function attaches the CharacterController (the player) to the current
// platform and also updates the parent when new platform is detected.
void FindCurrentPlatform()
{
if (isServer) {
if (Physics.Raycast (gameObject.transform.position, Vector3.down, out hitInfo)) {
if (hitInfo.transform.tag.Equals ("Platform")) {
parentHexagon = hitInfo.transform;
if (gameObject.transform.parent == null) {
print ("Parent set");
gameObject.transform.SetParent (parentHexagon);
}
}
}
}
}
void CmdHandleInput()
{
if (!isLocalPlayer)
return;
if (Input.GetButton ("Rotate"))
CmdRotateHexagon ();
[Command]
void CmdRotateHexagon()
{
HexagonController.instance.StartRotation ();
}
}
And here is the controller on hexagon that starts the animator.
public class HexagonController : NetworkBehaviour {
public static HexagonController instance;
public Transform hexagon;
Animator anim;
public bool rotate;
void Awake()
{
rotate = false;
instance = this;
}
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update ()
{
}
public void StartRotation()
{
anim.SetTrigger ("Rotate");
}
}
Edit: When i investigated the problem more closely, it seems that on the client side the hexagon is not rotating. That is why it seems that remote client player "goes" away from the point of rotation. However what i do not understand is that what component is missing that syncs the rotation. Ain't the Unity's networking system should take care of all this? Something is not syncing correctly.
Your answer
Follow this Question
Related Questions
How to decide an asynchronous multiplayer solution for a turn based mobile chess game? 0 Answers
UNET NetIDs for Scene Objects Mismatched Between Client and Server 1 Answer
[Multiplayer] How to invite friends to a lobby game? 0 Answers
Multiplayer non-player object synchronization,Synchronizing Objects in Multiplayer 0 Answers