• 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
2
Question by crtapps · Apr 15, 2013 at 05:44 AM · algorithmcurve

The algorithm of curve in Shuriken Particle System

Hi all,

Does anyone know what's the algorithm of curve that Shuriken Particle System used?

Is that a Bézier Curves?

Thanks.

Comment
Add comment · Show 1
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 crtapps · Apr 15, 2013 at 10:41 AM 0
Share

No one know?:(

2 Replies

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

Answer by Bunny83 · Apr 15, 2013 at 02:14 PM

The Shuriken Particle System just uses Unity's AnimationCurve class and the built-in editor. Yes they are bezier curves, but the control points are calculated by the "tangent angle".

edit

Finally had some time and i quickly created an editor window with a CurveField. This is the result:

Curve

Here's the most important part of my sample code:

     float w = R.width;
     float h = R.height;
     var keys = curve.keys;
     for(int i = 0; i < keys.Length-1;i++)
     {
         Keyframe K1 = keys[i];
         Keyframe K2 = keys[i+1];
         Vector2 start = new Vector2(K1.time*w,K1.value*h);
         Vector2 end = new Vector2(K2.time*w,K2.value*h);
         float d = (end.x-start.x) / 3.0f;
         float a = h / w;
         Vector2 st = start + new Vector2(d,d*a*K1.outTangent);
         Vector2 et = end + new Vector2(-d,-d*a*K2.inTangent);
         Drawing.BezierLineGL(start,st,end, et,Color.red,20);
     }

So basically you just take 1/3 of the distance between two points on the x-axis as the x position of the control point. When your viewing area's aspect ratio differs from 1.0 you have to correct the y value accordingly (like i did).

So at the end you have a start point (start) two control points (st, et) and the end point (end) for each segment to draw a cubic bezier between two KeyFrames.

ps: R is a Rect which represents the drawing area's size.


curvesample.png (31.0 kB)
Comment
Add comment · Show 15 · 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 crtapps · Apr 15, 2013 at 03:03 PM 0
Share

Thanks Bunny.It's very helpful for me.

avatar image crtapps · Apr 16, 2013 at 10:22 AM 0
Share

Another question, If the curves in Shuriken Particle System is Bezier, How do I apply the tangent parameter to the curve? e.g, If I changed the inTangent and outTangent member variable of $$anonymous$$eyframes in AnimationCurve(AnimationCurve.keys), I watched the curve changed ,but why? the formula of Cubic Bezier curves does not have the parameter of tanget, right?

Thanks.

avatar image Bunny83 · Apr 16, 2013 at 11:24 AM 0
Share

As i said you have to calculate the control points yourself. The in and out tangent is not, like stated in the docs, an angle in degree but the tangent of the desired angle. InTangent is positive when co$$anonymous$$g in from below and outTangent is positive when going up. a value of 0 is flat positiveInfinity represents an immediate step.

avatar image crtapps · Apr 17, 2013 at 11:00 AM 0
Share

Thanks for your answer Bunny. I have understood the inTangent and outTanget in AnimationCurve. But how do I calculate the control points from tangent? I did not find the relevant information from google. Could you give me some tips or links about this area? Thanks.

avatar image Bunny83 · Apr 18, 2013 at 09:30 AM 1
Share

You will always use a cubic bezier which will connect your "curve points". The outTangent of the first point will be used to deter$$anonymous$$e the first control point and the inTangent of the second point will deter$$anonymous$$e the second control point. If i can find some time, when i'm home, i might try it myself.

I'm still extending my inApp editor features and a curve editor would be nice ;)

Show more comments
avatar image
0

Answer by Varaughe · Jul 25, 2020 at 05:09 PM

If you want to know what is the exact equation behind an AnimationCurve, you should check Runtime Curve Editor (from Unity Asset Store). The package replicates 100% the equation by which the Animation Curve built-in editor plots the curve. Also the package supports visually editing of pairs of curves, which is used in the particle editor.

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

14 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

Related Questions

Smoothing a path 1 Answer

Subdivide Bezier Curves 3 Answers

Curving an Horizontal Slider 2 Answers

Create Animation in unity3d only on one axis 0 Answers

Using iTween.PutOnPath 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