- Home /
mirror player camera using one camera
hi! i am working on a game, and a have a error that I can't seem to find the answer to it. when I have two players, the camera of the first player that joined first will use the second player camera, but the movement of the first player is still controlled by the first player. on the second player, it just uses the second player camera and control his own movements. here is the script: using System.Collections; using System.Collections.Generic; using UnityEngine; using Mirror;
public class PlayerLook : NetworkBehaviour
{
[Header("References")]
[SerializeField] PlayerMovement wallRun;
[SerializeField] private float sensX = 100f;
[SerializeField] private float sensY = 100f;
[SerializeField] Transform cam = null;
[SerializeField] Transform orientation = null;
float mouseX;
float mouseY;
float multiplier = 0.01f;
float xRotation;
float yRotation;
public bool isLooking = true;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
if (!isLocalPlayer) { return; }
if (isLooking == true)
{
look();
}
if (Input.GetKeyDown(KeyCode.Escape))
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
if (Input.GetKeyDown(KeyCode.Tab))
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
isLooking = false;
}
else if (Input.GetKeyUp(KeyCode.Tab))
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
isLooking = true;
}
}
public void look()
{
mouseX = Input.GetAxisRaw("Mouse X");
mouseY = Input.GetAxisRaw("Mouse Y");
yRotation += mouseX * sensX * multiplier;
xRotation -= mouseY * sensY * multiplier;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
cam.transform.rotation = Quaternion.Euler(xRotation, yRotation, wallRun.tilt);
orientation.transform.rotation = Quaternion.Euler(0, yRotation, 0);
}
}
here is a video showing it: https://youtu.be/1TqcXOZU-8Q
Your answer
Follow this Question
Related Questions
NetworkWriter GameObject has no NetworkIdentity 0 Answers
Pointing a health bar to client camera 1 Answer
couldn't see either client and host player in each's camera, 0 Answers
Using networking solutions with AWS or Playfab servers with databases 1 Answer
How do I update values and the transform of an object on the server's and client's side? 0 Answers