I am trying to get a simple networking game running in.
What I try to achieve: A 3D object is moved with WASD movement, either server or client can do this and both see the same movement changes.
What I am seeing now is the following: Server can move the object via WASD perfectly fine, the client sees every movement just as expected. Now on the client side I try to move the object via WASD…this works locally, but the server does not see any changes. Once the server moves the object again, the object on the client side gets translated to the position the server sees.
I thought setting “network authority” to “local player authority” would resolve my problem but it didnt.
Short version what I did:
- Create a new 3D object
- Add NetworkIdentity to it, set “Local Player Authority” to true
- Add NetworkTransform
- Add script that moves item via WASD
Content of my script:
void Update()
{
if (Input.GetKeyDown(KeyCode.J))
{
Vector3 position = this.transform.position;
position.x = position.x - speed;
this.transform.position = position;
}
if (Input.GetKeyDown(KeyCode.L))
{
Vector3 position = this.transform.position;
position.x = position.x + speed;
this.transform.position = position;
}
if (Input.GetKeyDown(KeyCode.I))
{
Vector3 position = this.transform.position;
position.y = position.y + speed;
this.transform.position = position;
}
if (Input.GetKeyDown(KeyCode.K))
{
Vector3 position = this.transform.position;
position.y = position.y - speed;
this.transform.position = position;
}
}
Could it be that changing a transform via script needs some kind of trigger to send changes over network? If so, why does work out of the box for the server and not for the client?