Hello!
I’m having some trouble with getting a single emission of 18,000 particles to rotate facing away from the center of a globe.
Because I don’t have access to the .LookAt() method that comes with a Unity transform component, I’m struggling to get each particle that is placed on the globe to rotate facing away from the center of the globe. I have tried using the emitParams.rotation3D and passing in a Quaternion.LookRotation(direction, Vector3.up).eulerAngles conversion but I get a strange result pictured below.
Below is part of the code that deals with initializing and positioning each emitted point on the globe.
public void InitializeParticleSystem()
{
pSystem = this.gameObject.AddComponent<ParticleSystem>();
var rend = pSystem.GetComponent<ParticleSystemRenderer>();
var em = pSystem.emission;
var shape = pSystem.shape;
var mainModule = pSystem.main;
Material particleMaterial = Resources.Load("Point") as Material;
pSystem.GetComponent<ParticleSystemRenderer>().material = particleMaterial;
shape.enabled = false;
em.rateOverTime = 0f;
rend.alignment = ParticleSystemRenderSpace.World;
mainModule.startSize = .01f;
mainModule.startSpeed = 0;
mainModule.startColor = new Color(255, 255, 255, 255);
mainModule.maxParticles = nodeCount;
mainModule.startLifetime = Mathf.Infinity;
// Get each of the 18,000 position values represented in
// latitude and longitude coordinates and convert them to Cartesian coordinates.
foreach (var item in jsonObjects.rootNodes)
{
SetParticlePositionAndRotation(SphericalToCartesian(item.latitude, item.longitude));
}
if (m_Particles == null || m_Particles.Length < pSystem.main.maxParticles)
{
m_Particles = new ParticleSystem.Particle[pSystem.main.maxParticles];
}
}
public void SetParticlePositionAndRotation(Vector3 particlePos)
{
var emitParams = new ParticleSystem.EmitParams();
emitParams.position = particlePos;
// Having trouble aglining particle to face away from center of the globe
Vector3 direction = particlePos - this.transform.position;
Quaternion rot = Quaternion.LookRotation(direction, Vector3.up);
emitParams.rotation3D = rot.eulerAngles;
pSystem.Emit(emitParams, 1);
}
Here is an image of what happens with I run the code above. As you can see they are rotating weirdly and not a flat square on the surface.
Here is an image of what I’m trying to do with each particle emitted on the globe.
I have tried using the same code rotating just a flat plane/sprite and it works but when I implement it with each particle it does not work using the emitParams.rotation3D
Any thoughts?
J