- Home /
Movement animation
How can I make a script that plays a animation when I press a movement key?
Comment
Best Answer
Answer by Kamuiyshirou · May 03, 2014 at 12:25 AM
using UnityEngine;
using System.Collections;
public class AddSpeedRigidBody : MonoBehaviour {
public float speed = 10.0F;
public float rotationSpeed = 100.0F;
void Update() {
float moveVertical = Input.GetAxis("Vertical") * speed;
float moveHorizontal = Input.GetAxis("Horizontal") * rotationSpeed;
moveVertical *= Time.deltaTime;
moveHorizontal *= Time.deltaTime;
transform.Translate(0, 0, moveVertical);
transform.Rotate(0, moveHorizontal, 0);
}
}
I don’t know if it is the other scripts but this one causes my player to freak out (wild flips and rotation) and I get an endless stream of errors about “toggle movement” not setup. Without this script though my player and camera move like I expect them to, but the player is inanimate as he moves.