- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
jonesy5747 · Jul 21, 2015 at 03:31 PM ·
animationunity 5javascriptmovementcar
Horizontal axis not working after animation
So, I have built a simple car game, and have attached a script that allows it to move on both axis'. I have created an animation, so that if the car turns upside down, there is an option to press the 'f' button and flip the car back to normal. Unfortunately, once the animation plays and the car flips back onto it's wheels, the car moves forwards and backwards, but doesn't rotate. I am really confused by this, and would appreciate it if someone could help me, thanks. I am using unity, and building a 3d game. Here is the Script:
var speed : float = 10.0;
var rotationSpeed : float = 100.0;
var CarFlip : Animator;
function Start () {
CarFlip.enabled = false;
}
function Update () {
var translation : float = Input.GetAxis ("Vertical") * speed;
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
transform.Translate (0, 0, translation);
transform.Rotate (0, rotation, 0);
if(Input.GetKeyUp(KeyCode.F)){
CarFlip.enabled = true;
}
if(Input.GetKeyDown(KeyCode.B)){
speed = 30;
}
if(Input.GetKeyUp(KeyCode.B)){
speed = 15;
}
}
Comment
Answer by Arustyred · Jul 20, 2017 at 07:54 PM
Did you set CarFlip.enabled back to false after the car flips over?