Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Unity Bare Bones Top-Down Controller C#
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed = 6.0F;
public float gravity = 20.0F;
private Vector3 moveDirection =;
public CharacterController controller;
void Start(){
// Store reference to attached component
controller = GetComponent<CharacterController>();
void Update()
// Character is on ground (built-in functionality of Character Controller)
if (controller.isGrounded)
// Use input up and down for direction, multiplied by speed
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
// Apply gravity manually.
moveDirection.y -= gravity * Time.deltaTime;
// Move Character Controller
controller.Move(moveDirection * Time.deltaTime);
Copy link

ishanchandane101 commented Nov 9, 2020

Thanks! Really saved me a lot of time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment