Skip to content

Instantly share code, notes, and snippets.

@William-ST
Created May 8, 2017 07:24
Show Gist options
  • Save William-ST/2eaf694a077b25b558ef6873a59fd55f to your computer and use it in GitHub Desktop.
Save William-ST/2eaf694a077b25b558ef6873a59fd55f to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/* https://www.mixamo.com */
public class Drive : MonoBehaviour {
float speed = 5.0F;
float rotationSpeed = 100.0F;
Animator anim;
void Start() {
anim = this.GetComponent<Animator> ();
}
void Update () {
float translation = Input.GetAxis ("Vertical") * speed;
float rotation = Input.GetAxis ("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
transform.Translate (0, 0, translation);
transform.Rotate (0, rotation, 0);
if (translation != 0) {
anim.SetBool ("isWalking", true);
anim.SetFloat ("characterSpeed", translation);
} else {
anim.SetBool ("isWalking", false);
anim.SetFloat ("characterSpeed", 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment