Skip to content

Instantly share code, notes, and snippets.

@eanakashima
Last active August 29, 2015 14:06
Show Gist options
  • Save eanakashima/48d4438f52ce98e29525 to your computer and use it in GitHub Desktop.
Save eanakashima/48d4438f52ce98e29525 to your computer and use it in GitHub Desktop.
wwcode game-making class 1 c#
using UnityEngine;
using System.Collections;
public class ControlMovement : MonoBehaviour {
public float speed;
public float gravity;
public CharacterController controller;
Vector3 moveDirection = Vector3.zero;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (controller.isGrounded) {
// calculate move direction from input
moveDirection = new Vector3(Input.GetAxis("Horizontal") * speed, 0, 0);
// transform move direction from local to world space
moveDirection = transform.TransformDirection(moveDirection);
}
// apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// move character
controller.Move (moveDirection * Time.deltaTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment