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 /
  • Help Room /
avatar image
3
Question by exoter · Nov 11, 2015 at 02:55 PM · animationparameters

Animation with parameters

Hi all,

So I'm trying to create animation in Unity(it is not imported animation). It's quite simple animation - I have a cube that I move from (0, 0, 0) to (1,1,1). So I have 2 keyframes. But I want to make my animation use parameters instead of hard coded values.

I found how to make the starting point dynamic and instead of using (0,0,0) it is using the current object position, but I can't find how to change the end animation position (1,1,1) from code to be (x,y,z). So basically my question is - Is there a way to change keyframe parameters from code(e.g. have animation with dynamic parameters). Note that I'm talking about animation parameters not animator parameters.

Regards Pavel

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
3
Best Answer

Answer by Baste · Nov 11, 2015 at 05:11 PM

Not really.

Animations are supposed to be read-only assets that's created in the editor (or an external program), and played back in real time. There are ways to edit the keyframes of an animation asset in scripting, but that's editor time scripts, and it won't work during gameplay.

What you want to do, though, is easy. The AnimationCurve class is freely available to use in scripts. If you have it as a public field on a MonoBehaviour, you can edit it through the inspector. You can also create AnimationCurves, add keyframes to them, and evaluate the curve completely from code.

The best way to do what you're trying to do is probably to use a public AnimationCurve, and interpret it's values as percentage towards the goal. A very easy example would be:

 public AnimationCurve moveCurve;
 public Vector3 target;

 private Vector3 startPoint;

 void Awake() {
     startPoint = transform.position;
 }

 void Update() {
     transform.position = Vector3.Lerp(startPoint, target, moveCurve.Evaluate(Time.time));
 }
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

47 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Corgi Engine - Attack Animation Won't Play From Idle 1 Answer

Why can't I delete animator parameters? 2 Answers

Have Animator ignore parameters, pass Animation state manually? 0 Answers

root motion problem. direction parameter set to 90 on start 0 Answers

The name animator does not exist in the current context... Help? 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