Network Transform synchronizes only rotation but not movement
I have a player prefab, which has Network Identity (Local Player Authority = true), Network transform and PlayerMovmentControl script:
using UnityEngine;
using UnityEngine.Networking;
public class PlayerMovmentControl : NetworkBehaviour {
public float m_Speed = 10f;
public float m_TurnSpeed = 180f;
private Rigidbody m_Rigidbody;
private float m_ForwardMovmentValue;
private float m_SidewardMovmentValue;
private float m_TurnValue;
private void Awake()
{
m_Rigidbody = GetComponent<Rigidbody>();
}
private void OnEnable()
{
m_ForwardMovmentValue = 0f;
m_SidewardMovmentValue = 0f;
}
void Update () {
if (isLocalPlayer)
{
m_ForwardMovmentValue = Input.GetAxis("Vertical");
m_SidewardMovmentValue = Input.GetAxis("Horizontal");
m_TurnValue = Input.GetAxis("Mouse X");
}
}
private void FixedUpdate()//Moving and turn the player
{
Move();
Turn();
}
private void Move()
{
Vector3 movment = (transform.forward * m_ForwardMovmentValue + transform.right * m_SidewardMovmentValue) * m_Speed * Time.deltaTime;
m_Rigidbody.MovePosition(m_Rigidbody.position + movment);
}
private void Turn()
{
float turn = m_TurnValue * m_TurnSpeed * Time.deltaTime;
Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
m_Rigidbody.MoveRotation(m_Rigidbody.rotation * turnRotation);
}
}
There is a Network Manager with player prefab registered.
In game only rotation is synchronized but not movement. What am I doing wrong?
without looking your code, is possible the position is updated, but some script changes it right after, so the result is like it does not change.
I've checked several times, nothing like this. Even, if there were, so why only not local players stand at the start?
Answer by UserNameIsAlredyTaken · Sep 04, 2018 at 12:53 PM
Solved!
In Network Transform I chose Transform Sync Mode = Sync Transform (Sync Rigidbody was). Docs says that this type of synchronization is for objects that are not controlled by physics system, which is my case.
Your answer
Follow this Question
Related Questions
Client not getting updated positions 0 Answers
Unity Mirror OnStartServer spawn GameObjects 1 Answer
Client's object spawn position and rotation network bug? 0 Answers
Unity UNet Correct Usage, Unity 5.4 Beta 0 Answers
Network Attributes details 0 Answers