Skip to content

Instantly share code, notes, and snippets.

@touyou
Created February 27, 2014 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save touyou/9246392 to your computer and use it in GitHub Desktop.
Save touyou/9246392 to your computer and use it in GitHub Desktop.
import UnityEngine
class Player (MonoBehaviour):
public speed as single = 8.0f
public gravity as single = 10.0f
public controller as CharacterController
public jumpSpeed as single = 6.0f
public moveDirection as Vector3
def Start ():
controller = GetComponent(CharacterController)
def Update ():
if (controller.isGrounded):
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"))
moveDirection = transform.TransformDirection(moveDirection)
moveDirection *= speed
if (Input.GetButton("Jump")):
moveDirection.y = jumpSpeed
moveDirection.y -= gravity * Time.deltaTime
controller.Move(moveDirection * Time.deltaTime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment