Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 dorpeleg · Jul 04, 2013 at 09:21 AM · animationrotationeuleranglesanimationcurve

AnimationClip.SetCurve "localEulerAngles" not working

Hello everyone.

I have another issue with the SetCurve function.

I'm trying to set a rotation curve along the Z axis.

Here is my line of code:

 clip.SetCurve("objectname", typeof(Transform), "localEulerAngles.z", rotZcurve);

The data I'm putting in the curve is defiantly not empty.

When I open the Animation editor (this has nothing to do with mecanim),

I get the "Clean Up Leftover Curves" Button.

When I click it, I see all the Z rotation I'm trying to do....

Any ideas why unity think my Z rotation is empty?

Thanks!

Edit

Appearntly it has somthing to do with EulerAngles.

As soon as a change to localRotation, the curve does appear.

The problem is, localRotation uses quaternions.

No matter what I tried to do, I always get the rotation jumping between -180,0 and 180....

Can anyone help me figure it out?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
10
Best Answer

Answer by dorpeleg · Jul 11, 2013 at 08:08 AM

Figured it out.

Apparently, when setting a quaternion rotation, you need to provide the values for the vector4.

So here is what I did:

 var rotXcurve = new AnimationCurve();
 var rotYcurve = new AnimationCurve();
 var rotZcurve = new AnimationCurve();
 var rotWcurve = new AnimationCurve();

 var angle = Quaternion.Euler(0, 0, NeededRotation);

 rotXcurve.AddKey(Frame, angle.x);
 rotYcurve.AddKey(Frame, angle.y);
 rotZcurve.AddKey(Frame, angle.z);
 rotWcurve.AddKey(Frame, angle.w);

 clip.SetCurve(GO.name, typeof(Transform), "localRotation.x", rotXcurve);
 clip.SetCurve(GO.name, typeof(Transform), "localRotation.y", rotYcurve);
 clip.SetCurve(GO.name, typeof(Transform), "localRotation.z", rotZcurve);
 clip.SetCurve(GO.name, typeof(Transform), "localRotation.w", rotWcurve);

Hope this will help anyone.

Comment
Add comment · Show 2 · 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
avatar image halzate93 · Sep 24, 2014 at 01:02 AM 0
Share

Sir, you have definitely helped me a lot. I have been trying to figure this out for quite some time. Thank you.

avatar image soltex1 · Apr 02, 2016 at 06:02 AM 0
Share

Thank you! This helped me for some cases. However, there are some rotations values that doesn't work propertly, for instance Quaternion.Euler(100.23f, 46.05f, 0.53f) results in (79.76999, 226.05, 180.53) as keyframe, the direction is wrong I think... There is anyway to solve this?

avatar image
1

Answer by David-Flook · Jun 19, 2019 at 01:02 PM

Instead, you can use the following property names to set the curve in euler angles like you were attempting to do originally.

localEulerAnglesRaw.x

localEulerAnglesRaw.y

localEulerAnglesRaw.z

Comment
Add comment · Show 1 · 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
avatar image PersianKiller · Jun 05, 2021 at 02:01 AM 0
Share

thank you so much you are the best :)

I did it and it worked :)

 void Update(){
  
 
  
  if(Input.GetKeyDown(KeyCode.W)){
      
      changeXPos();
      
  }
  if(Input.GetKeyDown(KeyCode.S)){
      
      changeRot();
      
  }
  
  
  }
 
 
 public void changeXPos()
     {
     
 
     Keyframe[] keys;
     keys = new Keyframe[3];
      keys[0] = new Keyframe(0,0);
     keys[1] = new Keyframe(1,5);
     keys[2] = new Keyframe(2,18);

     var curve = new AnimationCurve(keys);

   clip.SetCurve("wa", typeof(Transform), "localPosition.x", curve);
     
     
     }
   
   
   
     public void changeRot()
     {
     
 
     Keyframe[] keys;
     keys = new Keyframe[3];
     keys[0] = new Keyframe(0,0);
     keys[1] = new Keyframe(1,5);
     keys[2] = new Keyframe(2,15);

     var curve = new AnimationCurve(keys);

 
      clip.SetCurve("wa", typeof(Transform), "localEulerAnglesRaw.z", curve);
     
     
     }
   
   

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

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't Accurately Read Rotations 0 Answers

AnimationClip.SetCurve not setting a curve... 0 Answers

Rotation problem while dynamically changing animations 2 Answers

Unity4.5 AnimationCurve - Is the property "_MainTex.rotation" valid ? 0 Answers

Evaluating Animation Curves in Full 0 Answers


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