Skip to content

Instantly share code, notes, and snippets.

@worthingtonjg
Last active October 25, 2019 20:49
Show Gist options
  • Save worthingtonjg/6599ab5e36d9f7151943f43dc4f4847b to your computer and use it in GitHub Desktop.
Save worthingtonjg/6599ab5e36d9f7151943f43dc4f4847b to your computer and use it in GitHub Desktop.
Character Controller - Simple Move
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