x


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);
}


}
more ▼

asked Jun 27 '11 at 04:55 PM

anwe gravatar image

anwe
114 31 34 38

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jun 27 '11 at 06:32 PM

EytanTKing gravatar image

EytanTKing
24 9 13 21

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5050
x3768
x2155
x35

asked: Jun 27 '11 at 04:55 PM

Seen: 630 times

Last Updated: Jun 27 '11 at 06:32 PM