all characters looking around problem..

Hey guys i made this mouse look script for a single player game long ago and now im trying to convert it into multiplayer could someone help me i’ve removed all my mutliplayer code because it wasn’t working please help me! :slight_smile: My problem right now is that if i look around with 1 character/game it let’s all my games look around

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class camMouseLook : MonoBehaviour
{

    Vector2 mouseLook;
    Vector2 smoothV;
    public float sensitivity = 5.0f;
    public float smoothing = 2.0f;

    GameObject character;

    private void Start()
    {
        character = this.transform.parent.gameObject;
    }

    void Update()
    {
        var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxis("Mouse Y"));

        md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
        smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
        smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
        mouseLook += smoothV;
        mouseLook.y = Mathf.Clamp(mouseLook.y, -90f, 90f);

        transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
        character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
    }
}

Just put something in Update() that checks to see if this client owns the object. If it doesn’t, just return;.

I tried this: if (!isLocalPlayer) return; but it didn’t work…

Show us that code. As is right now, you inherit from MonoBehavior which does not have a isLocalPlayer field. My guess is that you didn’t spawn your object on the network.

This is it:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class camMouseLook : NetworkBehaviour
{

    Vector2 mouseLook;
    Vector2 smoothV;
    public float sensitivity = 5.0f;
    public float smoothing = 2.0f;

    GameObject character;

    private void Start()
    {
        character = this.transform.parent.gameObject;
    }

    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxis("Mouse Y"));

        md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
        smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
        smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
        mouseLook += smoothV;
        mouseLook.y = Mathf.Clamp(mouseLook.y, -90f, 90f);

        transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
        character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
    }
}

First off, you can only have a single NetworkIdentity component per gameobject with no NetworkIdentity components on child objects. The NetworkIdentity component has to be on the root gameobject. NetworkBehaviour components have to be on the same gameobject as the NetworkIdentity component, so also need to be on the root gameobject.

The way you are grabbing the reference to your character object in Start says that you’re putting this on a child object, which is not supported.