- Home /
animations not working correctly in build
Hello,
I have a character on a bike that animates left and right into a lean position depending on which arrow key you hit. The animations were baked in from 3d max and are set to *clamp forever*. Everything works perfectly in the editor but when I build it to a web player it sometimes won't play the animation when I'm pressing the Up Arrow(accelerate) and the Left/Right Arrow(lean) at the same time, but does play it when only the Left/Right Arrow is pressed. I've tried about everything I can think of so any ideas would be great.
Here's the code :
var minAngle = 0.0; var maxAngle = 10.0; var toLeft : Transform;//bike lean left// var toRight : Transform;//bike lean right// var toCenter : Transform;//bike lean center// var speed = 4;//speed of lean// var returnCenter : boolean = false;//tells script it's ok to center bike// var bikeObject : GameObject; static var goRace : boolean = false; var Biker : GameObject; static var leftLean : boolean = false; static var rightLean : boolean = false;
function Awake() { goRace = false; leftLean = false; rightLean = false; }
function Update () { if (goRace) { //when game is ready this is set to true//
if (Input.GetKey("left")) {
returnCenter = false;
transform.rotation = Quaternion.Slerp (transform.rotation, toLeft.rotation, Time.deltaTime * speed);
Biker.animation.CrossFade ("LeanLeftB");
leftLean = true;
rightLean = false;
} else {
if (Input.GetKey ("right")) {
returnCenter = false;
transform.rotation = Quaternion.Slerp (transform.rotation, toRight.rotation, Time.deltaTime * speed);
Biker.animation.CrossFade ("LeanRightB");
leftLean = false;
rightLean = true;
}
}
if (Input.GetKeyUp ("left")) {
leftLean = true;
returnCenter = true;
Biker.animation.CrossFade ("LeanLeftBackB");
} else {
if (Input.GetKeyUp ("right")) {
rightLean = true;
returnCenter = true;
Biker.animation.CrossFade ("LeanRightBackB");
}
}
if (Input.GetKey("left") && Input.GetKey("up")) {
returnCenter = false;
transform.rotation = Quaternion.Slerp (transform.rotation, toLeft.rotation, Time.deltaTime * speed);
Biker.animation.CrossFade ("LeanLeftB");
leftLean = true;
rightLean = false;
} else {
if (Input.GetKey ("right") && Input.GetKey("up")) {
returnCenter = false;
transform.rotation = Quaternion.Slerp (transform.rotation, toRight.rotation, Time.deltaTime * speed);
Biker.animation.CrossFade ("LeanRightB");
leftLean = false;
rightLean = true;
}
}
if (returnCenter) {
transform.rotation = Quaternion.Slerp (transform.rotation, toCenter.rotation, Time.deltaTime * speed);
if (leftLean){
leftLean = false;
Biker.animation.CrossFade ("LeanLeftBackB");
}
if (rightLean){
rightLean = false;
Biker.animation.CrossFade ("LeanRightBackB");
}
}
//Debug.Log(transform.rotation);
}
}
Answer by ThumbStorm · Jan 14, 2011 at 04:35 AM
After cursing over and over and truing everything under the sun it turns out all I had to do is add add the fade length in the CroosFade ex. OLD - Biker.animation.CrossFade ("LeanLeftB"); NEW - Biker.animation.CrossFade ("LeanLeftB", .3);
That was a day and a half I'll never get back. Hope this helps anyone else who has the same problem.
Your answer
![](https://koobas.hobune.stream/wayback/20220613095217im_/https://answers.unity.com/themes/thub/images/avi.jpg)