- Home /
Question by
GH0STfdd · Jul 24, 2016 at 08:43 AM ·
camerainputmultiplayer
Multiplayer players moving with same input
Ok,so,every spawned player is having the same scripts and own camera but all players is moving with same input,when i'm rotating the mouse both players are moving to it's position and shoot at same time...how to fix it? here's the player script :
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class Engine : NetworkBehaviour
{
Vector3 position;
public GameObject player;
public float speed;
public float flySpeed;
public Camera mainCamera;
void Start()
{
if (GetComponent<NetworkView> ().isMine)
{
Instantiate (mainCamera, new Vector3 (player.transform.position.x, 101.1f, player.transform.position.z), Quaternion.Euler (90, 0, 0));
}
}
void Update()
{
if (GetComponent<NetworkView> ().isMine)
{
player = this.gameObject;
}
IncreasePosition ();
MoveToPosition ();
Cursor.visible = false;
}
public override void OnStartLocalPlayer()
{
GetComponent<MeshRenderer> ().material.color = Color.blue;
}
void IncreasePosition()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit, 1000000))
{
position = new Vector3 (hit.point.x, hit.point.y, hit.point.z);
}
}
void MoveToPosition()
{
Quaternion newRotation = Quaternion.LookRotation (position - transform.position, Vector3.up);
newRotation.z = 0f;
newRotation.x = 0f;
transform.rotation = Quaternion.Slerp (transform.rotation, newRotation, Time.deltaTime * 6);
player.transform.Translate (Vector3.forward *flySpeed* Time.deltaTime);
}
}
/////////////////////////////////////////////////////////////////////////////////////////// And camera's :
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class CameraMotor : NetworkBehaviour
{
public Vector3 offset;
public GameObject player;
void Start()
{
if (GetComponent<NetworkView>().isMine)
{
GetComponent<Camera>().enabled = true;
player = GameObject.Find ("Plane(Clone)");
}
else
{
GetComponent<Camera>().enabled = false;
}
offset = transform.position;
}
void LateUpdate()
{
//if (player == null)
//{
// player = GameObject.Find ("Plane(Clone)");
//}
//else
//{
transform.position = player.transform.position + offset;
//}
}
}
Comment
Your answer
Follow this Question
Related Questions
Gamepad and Keyboard camera rotate 0 Answers
Cinemachine Input Provider requires InputActionReference. Any workarounds? 0 Answers
[New Player Input System] Separate players in scene 0 Answers
PlayerInput - SendMessages not working after changing the scene 1 Answer
I need to make the Camera Quit snapping to center... 1 Answer