Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
6
Question by Prefab · Jun 24, 2016 at 02:34 AM · animationvariablecurveanimationcurve

Can Animation Curves be used to control variables?

I have 2 basic float variables; distance and damage. The damage variable changes based on the distance variable. At the moment I have several damage variables due to the number of times the damage changes over distance (eg. 50 dmg between 0-20m, 30 dmg between 20-40m etc).

alt text

I noticed that the standard asset FPS controller uses an animation curve to control its slope curve modifier. I have never used the animation curve variable type, but I'm wondering if it is possible to use it for my particular case? For example, if I could make the y axis = damage, and the x axis = distance then I could create a single animation curve that represents this instead of having 6 separate variables. Is this possible with animation curves?

I have had a look at the FPS controller script but I do not quite understand how it is using the animation curve to read values from it and translating those into logic. I think it might involve the Evaluate function but there isn't an example in the docs.

Can this be done?

screenshot-24-06-2016.png (2.9 kB)
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
14
Best Answer

Answer by Prefab · Jun 27, 2016 at 06:00 AM

Ok I have managed to work this out. It is a bit confusing and isn't properly explained anywhere but here goes. First you need to declare an AnimationCurve variable. Then open the curve editor of this variable and use the Y axes for damage and the X axes for distance. Create your keyframes depending on how you want the damage to change over distance. Then you simply need to make the damage equal to the AnimationCurve evaluated. Here is a snippet to demonstrate this:

 distanceTravelled = Vector3.Distance(firingPosition, transform.position);
 damage = damageCurve.Evaluate(distanceTravelled);

This is actually very powerful. I am surprised that it isn't documented better anywhere.

Comment
Add comment · Show 4 · 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 alexanderameye · Oct 16, 2016 at 01:36 PM 0
Share

I need to achieve the same thing, thanks for answering your question :)

avatar image Hogge · Apr 08, 2017 at 06:58 PM 0
Share

I want to achieve the same thing and this really helped me out. Thing is, the numbers I'm working with are larger than 0-1. What I'm doing is calculating air density, with the altitude range being 0-3500 meters. How can I rescale the curve to fit?

avatar image Ryutsashi Hogge · May 18, 2017 at 05:26 PM 0
Share

If you want to convert a 0-1 value (from here on curveValue) to some other scale, simply multiply it. This is your case:

Case: 0-3500

convertedValue = curveValue * 3500;

Since 0*3500 equals 0 and 1*3500 equals 3500 every in-between value will map from 0-3500.

If you need saaaay... -100-500, you could write it like this:

convertedValue = curveValue * 600 - 100;

All in all, there is no reason to modify the curve, you simply modify it's output. The rest is basic math.

avatar image echolink · Aug 09, 2018 at 10:48 AM 0
Share

This really help me as starting point to do what i want thanks

avatar image
1

Answer by Arclite83 · Jul 16, 2021 at 03:04 PM

Personal tip: normalize your curves. It's far easier to do the math if X and Y are both 0-1, and your multipliers are elsewhere (other editor variables, probably, but just as easily coming from completely different systems).

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

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

Related Questions

How to make an Animation layer not set curve parameters? 0 Answers

How to animate a MeshRenderer color in Unity3D? 1 Answer

How to Change (CENTER x ,y,z) of Capsule Collider Animation from Curve ? C# 1 Answer

Prevent keyframe interpolation in imported model animation in Unity 1 Answer

How to Change Capsule Collider (CENTER x ,y,z) Animation with Curve ? C# "Positive7 why?" 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