• 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 (t$$anonymous$$s has not$$anonymous$$ng 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 t$$anonymous$$nk my Z rotation is empty?

Thanks!

Edit

Appearntly it has somt$$anonymous$$ng 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 t$$anonymous$$s 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
avatar image soltex1 · Apr 02, 2016 at 06:02 AM 0
Share
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

SetCurve not working for me. 1 Answer

Change animation depending on an angle the character is facing? (2d) 0 Answers

How to Move the rotated Game Object Forward 0 Answers

SetCurve rotation behaviour 0 Answers

Transition between rotations 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