Added PlayerMovement and other
This commit is contained in:
@@ -3,19 +3,11 @@ using UnityEngine;
|
||||
|
||||
public class PlayerController : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private float moveSpeed = 5f;
|
||||
|
||||
[SerializeField] private Camera playerCamera;
|
||||
[SerializeField] private Camera playerHandCamera;
|
||||
[SerializeField] private GameObject tpvHands;
|
||||
[SerializeField] private GameObject fpvHands;
|
||||
|
||||
|
||||
[SerializeField] private float mouseSensitivity = 2f;
|
||||
[SerializeField] private Transform cameraRoot;
|
||||
|
||||
float verticalRotation = 0f;
|
||||
|
||||
public override void OnNetworkSpawn()
|
||||
{
|
||||
if (playerCamera != null)
|
||||
@@ -38,39 +30,5 @@ public class PlayerController : NetworkBehaviour
|
||||
{
|
||||
meshRenderer.material.color = playerColor;
|
||||
}
|
||||
|
||||
// if (IsOwner)
|
||||
// {
|
||||
// transform.position = new Vector3(Random.Range(-10f, 10f), 1f, Random.Range(-10f, 10f));
|
||||
// }
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if(!IsOwner) return;
|
||||
|
||||
HandleMovement();
|
||||
HandleRotation();
|
||||
}
|
||||
|
||||
private void HandleMovement()
|
||||
{
|
||||
float _moveX = Input.GetAxis("Horizontal");
|
||||
float _moveZ = Input.GetAxis("Vertical");
|
||||
|
||||
Vector3 move = transform.right * _moveX + transform.forward * _moveZ;
|
||||
transform.position += move * moveSpeed * Time.deltaTime;
|
||||
}
|
||||
|
||||
private void HandleRotation()
|
||||
{
|
||||
float _mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
|
||||
float _mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
|
||||
|
||||
transform.Rotate(Vector3.up * _mouseX);
|
||||
|
||||
verticalRotation -= _mouseY;
|
||||
verticalRotation = Mathf.Clamp(verticalRotation, -90f, 90f);
|
||||
cameraRoot.localRotation = Quaternion.Euler(verticalRotation, 0f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user