namespace PivecLabs.Minimap { using System.Collections; using System.Collections.Generic; using UnityEngine; public class movePlayer : MonoBehaviour { CharacterController characterController; public float speed = 6.0f; public float gravity = 50.0f; public float rotationspeed = 240.0f; private Vector3 moveDirection = Vector3.zero; void Start() { characterController = GetComponent(); } void Update() { Vector3 camForward_Dir = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized; Vector3 moveDirection = Input.GetAxis("Vertical") * camForward_Dir + Input.GetAxis("Horizontal") * Camera.main.transform.right; if (moveDirection.magnitude > 1f) moveDirection.Normalize(); moveDirection = transform.InverseTransformDirection(moveDirection); float turnAmount = Mathf.Atan2(moveDirection.x, moveDirection.z); this.transform.Rotate(0, turnAmount * rotationspeed * Time.deltaTime, 0); if (characterController.isGrounded) { moveDirection *= speed; moveDirection = transform.forward * moveDirection.magnitude; } moveDirection.y -= gravity * Time.deltaTime; characterController.Move(moveDirection * Time.deltaTime); } } }