Hi,
I’m comparatively new to Unity still, but seem to be muddling through without too much issue. I have however come across one particularly infuriating issue I’m finding myself unable to resolve.
I have a player prefab object that gets spawned into the world when a new player joins the game. The issue is that client-controlled prefabs, aren’t sending their position to the server.
The server host’s player object is correctly synced.
Any additional clients created on the host machine are also synced.
3rd party clients (on different machines) can see and follow the host objects without issue and see the game correctly.
No-one else can see the movement of these 3rd party playerobjects.
I really am at a loss as to why a client on the same machine as the host (aka 2 copies of the game) works, but a separate machine does not.
To move the player, I’m using the standard transform command after checking for isLocalPlayer. There are no errors in compiling.
To sync the objects, they have the network transform and network identity as below:
Any ideas or assistance would be greatly appreciated!
For completeness sake, here’s the movement control code:
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class characterController : NetworkBehaviour {
public float speed = 10.0F;
float lastJump = 0.0F;
public Texture2D crosshair;
public Transform cubetemplate;
public console console;
void OnGUI() {
if (!isLocalPlayer) {
return;
}
float xMin = (Screen.width / 2) - (crosshair.width / 2);
float yMin = (Screen.height / 2) - (crosshair.height / 2);
GUI.DrawTexture (new Rect (xMin, yMin, crosshair.width, crosshair.height), crosshair);
}
void Start () {
Cursor.lockState = CursorLockMode.Locked;
if (!isLocalPlayer) {
Destroy(transform.GetComponentInChildren ());
Destroy(transform.GetComponentInChildren ());
}
}
void Update () {
if (!isLocalPlayer || console.InputEnabled) {
return;
}
float translation = Input.GetAxis (“Vertical”) * speed;
float straffe = Input.GetAxis (“Horizontal”) * speed;
float jump = Input.GetAxis (“Jump”);
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
Rigidbody rb = GetComponent ();
rb.position = rb.position + transform.TransformDirection (new Vector3(straffe, 0, translation));
if (Input.GetKeyDown (“`”)) {
Cursor.lockState = CursorLockMode.None;
}
if (jump > 0 && lastJump == 0) {
RaycastHit hit;
if (Physics.SphereCast (transform.position, 0.5f, -transform.up, out hit, 1.2f)) {
if (rb.velocity.y * rb.velocity.y / 2 < 2) {
rb.AddForce (transform.up * 7, ForceMode.Impulse);
}
}
}
lastJump = jump;
}
//additional non-movement based code
}