Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Animating (simple rotation) armature by script 1 Answer

Animate a cube rotation with script only 3 Answers

Rolling cubes one space and one rotation at a time, with a delay 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Using Quaternions and C# script to animate a mesh 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges