Hello everyone,
i need to position particles in a Teardrop-Shape (3D).
For this purpose i need an parametric equation for an Vector.
So far i have this equation:
public Vector3 Eval(float theta, float phi)
{
Vector3 p;
p.x = 0.5f * (1f - Mathf.Cos(theta)) * Mathf.Sin(theta) * Mathf.Cos(phi);
p.y = 0.5f * (1f - Mathf.Cos(theta)) * Mathf.Sin(theta) * Mathf.Sin(phi);
p.z = Mathf.Cos(theta);
return (p);
}
But i don’t know how to use it in the right way.
I want to set the position dependent of three parameters:
first: distance from the center
second: height
third: radius (if you look from top to bottom)
I hope i could express myself in the right way because I am not an English native speaker.
Can anyone help me?
I am grateful for any hint.
Here, try this
It’s up to you how many you emit per frame - just call the code in a loop to emit many times per frame.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class teardrop : MonoBehaviour {
private ParticleSystem ps;
public float sizeMultiplier = 1.0f;
public float heightMultiplier = 1.0f;
public float radiusMultiplier = 1.0f;
// Use this for initialization
void Start () {
ps = GetComponent<ParticleSystem>();
var main = ps.main;
main.startSpeed = 0.0f;
main.startSize = 0.05f;
var emission = ps.emission;
emission.enabled = false;
}
// Update is called once per frame
void Update () {
float theta = Random.Range(0.0f, 1.0f);
float phi = Random.Range(0.0f, 1.0f);
ParticleSystem.EmitParams emitParams = new ParticleSystem.EmitParams();
emitParams.position = Eval(theta * Mathf.PI * 2.0f, phi * Mathf.PI) * sizeMultiplier;
emitParams.startColor = new Color(0.0f, phi, 0.0f);
ps.Emit(emitParams, 1);
}
private Vector3 Eval(float theta, float phi)
{
float sinT = Mathf.Sin(theta);
float cosT = Mathf.Cos(theta);
Vector3 p;
p.x = 0.5f * (1f - cosT) * sinT * Mathf.Cos(phi) * radiusMultiplier;
p.y = 0.5f * (1f - cosT) * sinT * Mathf.Sin(phi) * radiusMultiplier;
p.z = cosT * heightMultiplier;
return (p);
}
}
No problem, good luck!
As you have cited, the Sine and Cosine graphs are very useful for creating circular shapes.
You can see that being used for the X and Y axes in your code. The Z is created using a different part of the Cosine graph, to create the tear, instead of a regular sphere.
It may help you to look at the graphs of Sine and Cosine. You should be able to visualise how they are appearing in the final teardrop shape.