Question by
farhad.wafa · Dec 13, 2015 at 07:37 PM ·
networkingmultiplayercharactercontroller
Multiplayer / LocalPlayer cannot move with CharacterController, why?
Hello everybody,
I try to make a multiplayer game and have only one problem: the local player cannot move. I used a CharacterController and call it in the Start() function. In the Move() function I used controller.move . It doesnt'nt work. All the other things are working fine. Can anybody help me, please? Here is my Code:
public class PlayerControllerNetwork : NetworkBehaviour {
public float walkSpeed;
private bool isMoving;
private Vector3 moveDirection;
private CharacterController controller;
public Camera cameraLeft, cameraRight;
void Start()
{
if (isLocalPlayer)
{
GetComponentInChildren<OpenDiveSensor>().enabled = true;
GetComponentInChildren<MouseLook>().enabled = true;
GetComponentInChildren<OffsetCenter>().enabled = true;
GetComponentInChildren<PlayerControllerScriptNetwork>().enabled = true;
GetComponentInChildren<RaycastingForMovementPauseTrigger>().enabled = true;
GetComponentInChildren<health>().enabled = true;
GetComponentInChildren<StickOnObject>().enabled = true;
GetComponentInChildren<InfoPanel>().enabled = true;
GetComponentInChildren<CountPickups>().enabled = true;
GetComponentInChildren<Timer>().enabled = true;
cameraLeft.enabled = true;
cameraRight.enabled = true;
controller = GetComponentInChildren<CharacterController>();
this.isMoving = false;
moveDirection = Vector3.zero;
}
}
void Update()
{
if (!isLocalPlayer)
return;
if (this.isMoving)
{
GenerateMovementVector();
Move();
}
}
void Move()
{
controller.Move(moveDirection * Time.deltaTime);
}
void GenerateMovementVector()
{
this.moveDirection = this.transform.forward;
this.moveDirection.y = 0;
this.moveDirection *= walkSpeed;
}
public override void OnStartLocalPlayer()
{
base.OnStartLocalPlayer();
GetComponentInChildren<MeshRenderer>().material.color = Color.red;
}
}
Comment