- Home /

# 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.

**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:

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.

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 Keyframes 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.

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 coming in from below and outTangent is positive when going up. a value of 0 is flat positiveInfinity represents an immediate step.

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.

You will always use a cubic bezier which will connect your "curve points". The outTangent of the first point will be used to determine the first control point and the inTangent of the second point will determine 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 ;)

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Smoothing a path 1 Answer

Subdivide Bezier Curves 3 Answers

create a ground using bezier curve 2 Answers

Marching cubes in Unity? 1 Answer

Get connected vertices 0 Answers