Question by
OctoMan · Apr 13, 2016 at 09:05 PM ·
particle systemshurikencurve
Coding a Sine / Cosine Wave for the Particle System
I want to code a sine wave and later cosinus curve for the shuriken particle system. But i'm stuck. I want to defind with how many points the curve gets created and with how many complete degrees the curve should be shown. As base 360 degrees for 1 complete sine wave.
Currently i have:
void CreateCircle()
{
ParticleSystem PS = GetComponent<ParticleSystem>();
var vel = PS.velocityOverLifetime;
vel.enabled = true;
vel.space = ParticleSystemSimulationSpace.Local;
AnimationCurve curveX = new AnimationCurve();
float points = 10 * repeat;
for (int i = 0; i < points; i++)
{
float newtime = i / (points - 1);
float myvalue = Mathf.Sin(i*360);
curveX.AddKey(newtime,myvalue);
Debug.Log(newtime);
}
vel.x = new ParticleSystem.MinMaxCurve(10.0f, curveX);
}
So i want to create the x curve with 10 points at first. What have i done wrong? I hope somebody can help me out. Thanls in advance.
Comment
Answer by M-Hanssen · Apr 14, 2016 at 09:45 AM
Didn't you forget to modify the lifetime of the particles?
protected void CreateCircle()
{
ParticleSystem ps = GetComponent<ParticleSystem>();
ps.startLifetime = Repeat;
ParticleSystem.VelocityOverLifetimeModule vel = ps.velocityOverLifetime;
vel.enabled = true;
vel.space = ParticleSystemSimulationSpace.Local;
AnimationCurve curveZ = new AnimationCurve();
float points = 10 * Repeat;
for (int i = 0; i < points; i++)
{
float newtime = i / (points - 1);
float myvalue = Mathf.Sin(i * 360);
curveZ.AddKey(newtime, myvalue);
Debug.Log(newtime);
}
Nope, i just figured i calculated the sine wave wrong.
int frequency = 1;//repeatrate
float resolution = 10;//the pointamount used to create the wave
for (int i = 0; i < resolution; i++)
{
float newtime = (i/(resolution-1));
float myvalue = $$anonymous$$athf.Sin(newtime * (frequency * 2) * $$anonymous$$athf.PI);
curveX.Add$$anonymous$$ey(newtime,myvalue);
}
Still thanks for your time and affort.