Last active
October 25, 2019 20:49
-
-
Save worthingtonjg/6599ab5e36d9f7151943f43dc4f4847b to your computer and use it in GitHub Desktop.
Character Controller - Simple Move
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player : MonoBehaviour | |
{ | |
public float rotationSpeed = 4f; | |
public float moveSpeed = 25f; | |
private CharacterController characterController; | |
private float yaw = 0f; | |
// Start is called before the first frame update | |
void Awake() | |
{ | |
characterController = GetComponent<CharacterController>(); | |
Cursor.lockState = CursorLockMode.Locked; | |
Cursor.visible = false; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
yaw += Input.GetAxis("Mouse X") * rotationSpeed; | |
Vector3 moveDir = transform.forward * Input.GetAxis("Vertical") * moveSpeed; | |
transform.eulerAngles = new Vector3(0f, yaw, 0f); | |
moveDir += transform.right * Input.GetAxis("Horizontal") * moveSpeed; | |
characterController.SimpleMove(moveDir); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment