- Home /
 
 
               Question by 
               anwe · Jun 27, 2011 at 04:55 PM · 
                animationrotationhelicopter  
              
 
              Problem with animation: they always start at the same rotation!!
I have an helicopter with a script which plays different animation depending on the inputs. The problem is that 1)When I rotate it in the scene view and I press Play it starts at the same rotation(0,0,0) 2)When I play an animation that rotates itself it always begin at the rotation (0,0,0). However, Here's the code:
 #pragma strict
 var eliche : Transform[];
 //Uso animationState x effettuare il blending successivo
 private var idle : AnimationState;
 private var back : AnimationState;
 private var forward : AnimationState;
 private var left : AnimationState;
 private var right : AnimationState;
 private var turnLeft : AnimationState;
 private var turnRight : AnimationState;
 //Settaggio di tutte le variabili e funzioni in partenza
 function Start(){
 animation.Stop();
  
 turnLeft = animation["turnLeft"];
 turnRight = animation["turnRight"];
 idle = animation["idle"];
 back = animation["back"];
 forward = animation["forward"];
 left = animation["left"];
 right = animation["right"];
  
 turnLeft.blendMode = AnimationBlendMode.Blend;
 turnRight.blendMode = AnimationBlendMode.Blend;
  
 back.wrapMode = WrapMode.ClampForever;    
 forward.wrapMode = WrapMode.ClampForever;  
 left.wrapMode = WrapMode.ClampForever;  
 right.wrapMode = WrapMode.ClampForever;
 idle.wrapMode = WrapMode.ClampForever; 
  
 }
 function FixedUpdate () {
 if (Input.GetKey(KeyCode.Q)){
     transform.Translate(Vector3.up*Time.fixedDeltaTime*10);
 }
 else if (Input.GetKey(KeyCode.E)){
     transform.Translate(-Vector3.up*Time.fixedDeltaTime*10);
 }
 //esecuzione animazione
 if (Input.GetButton("Horizontal") || Input.GetButton("Vertical")){
     if (Input.GetAxis("Horizontal") > 0.000 && Input.GetAxis("Vertical") == 0.00){
         animation.CrossFade("right", 0.7);
     }
     else if (Input.GetAxis("Horizontal") < -0.00 && Input.GetAxis("Vertical") == 0.00){
         animation.CrossFade("left", 0.7);
     }
     else if (Input.GetAxis("Vertical") > 0.00 && Input.GetAxis("Horizontal") == 0.00){
         animation.CrossFade("forward", 0.7);
     }
     else if (Input.GetAxis("Vertical")  < -0.00 && Input.GetAxis("Horizontal") == 0.00){
         animation.CrossFade("back", 0.7);
     }
     else if (Input.GetAxis("Horizontal") > 0.00 && Input.GetAxis("Vertical") > 0.00){
         animation.CrossFade("forwardRight", 0.7);
     }
     else if (Input.GetAxis("Horizontal") > 0.00 && Input.GetAxis("Vertical")  < -0.00){
         animation.CrossFade("backRight", 0.7);
     }
     else if (Input.GetAxis("Horizontal") < -0.00 && Input.GetAxis("Vertical") > 0.00){
         animation.CrossFade("forwardLeft", 0.7);
     }
     else if (Input.GetAxis("Horizontal") < 0.00 && Input.GetAxis("Vertical")  < -0.00){
         animation.CrossFade("backLeft", 0.7);
     }
     
 }
 else if((Input.GetAxis("Horizontal") && Input.GetAxis("Vertical")) == 0.00 ){
     //animation.CrossFade("idle", 1);
 }
 if (Input.GetKey(KeyCode.Alpha1)){
     animation.CrossFade("turnLeft");
 }
 else if (Input.GetKeyUp(KeyCode.Alpha1)){
     animation.Stop("turnLeft");
 }
 else if (Input.GetKey(KeyCode.Alpha3)){
     animation.CrossFade("turnRight");
 }    
 else if (Input.GetKeyUp(KeyCode.Alpha3)){
     animation.Stop("turnRight");
 }
 
 //Debug.Log("Input Orizzontale è"+Input.GetAxis("Horizontal"));
 //Debug.Log("Input Verticale è"+Input.GetAxis("Vertical"));
 //Move(currentSpeedBackForward, currentSpeedLeftRight);
 }
 function LateUpdate(){
 //Ebbe, muoviamo le eliche
 for(var i: Transform in eliche){
 i.Rotate(Vector3(0,1,0)*100, Space.Self);
 }
 }
 
              
               Comment
              
 
               
              Answer by EytanTKing · Jun 27, 2011 at 06:32 PM
Put the helicopter in an empty object, then add all the moving (+ rotating) scripts to it. That way the helicopter is always rotated (0,0,0) in the empty object. so the animation will not give you rotating problems. In other words, kinda brake up all the jobs.
Your answer