my multiplayer UNITY game is making it so that players controll ALL OTHER PLAYERS.
in other words, my UNITY game is making it so that when my character moves forward, so does everyone elses, etc. for all directions.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
public float upspeed = 0.0F;
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
public float rospe = 3.0F;
private Vector3 moveDirection = Vector3.zero;
// Use this for initialization
// Update is called once per frame
void Update()
{
CharacterController controller = GetComponent<CharacterController>();
if (Input.GetKey(KeyCode.W))
{
transform.position += transform.forward * Time.deltaTime * speed;
}
if (Input.GetKey(KeyCode.E))
{
transform.position += transform.up * Time.deltaTime * upspeed;
}
if (Input.GetKey(KeyCode.Q))
{
transform.position -= transform.up * Time.deltaTime * upspeed;
}
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
controller.Move(moveDirection * Time.deltaTime);
//Rotation of player
transform.Rotate(0, Input.GetAxis("Horizontal"), 0);
}
}
@supercraftmcproductions it’s normal the code here is the controller code for all characters right? if the option script is attached to all you’re characters once you press a button all of them will receive the same command. depending on what you’re trying to achieve this can be solve by creating an other script for them or having a bool at the start of you’re update such as :
if(!isControllablePlayer) return; //if single player
As for local multiplayer you need to have 2 scripts each would take different buttons for movement or use 1 script and make the buttons ur using public variables and select each player’s buttons in the editor the best approach would be this in your case for local:
`
public class Controller : MonoBehaviour
{
public float upspeed = 0.0F;
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
public float rospe = 3.0F;
private Vector3 moveDirection = Vector3.zero;
public KeyCode up;
public KeyCode down;
public KeyCode left;
public CharacterController controller;
// Use this for initialization
void Start()
{
controller = GetComponent();
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(up))
{
transform.position += transform.forward * Time.deltaTime * speed;
}
if (Input.GetKey(down))
{
transform.position += transform.up * Time.deltaTime * upspeed;
}
if (Input.GetKey(left))
{
transform.position -= transform.up * Time.deltaTime * upspeed;
}
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
controller.Move(moveDirection * Time.deltaTime);
//Rotation of player
transform.Rotate(0, Input.GetAxis("Horizontal"), 0);
}
}
`
as for online it will depend on the system you’re using but adding you need to condition it depending on the player’s NetworkIdentity
but this all depends if this is a single player an online game or a local multiplayer.
@dargonknight its local multiplayer. i know that its normal, i just couldnt figure it out. would doing if(!isControllablePlayer) return; make it so that would work, cause it doesent seem like it.