- Home /
is it possible to make a custom gravity modifier to affect a particle system, ignoring the general scene's gravity?
Somebody know if its possible to make a custom gravity modifier to affect a particle system, ignoring the general scene's gravity? because the particle system's gravity modifier works on the current gravity axis setted on the physics settings.
Answer by RealSoftGames · Apr 14, 2017 at 04:07 AM
yes its possible this will need tweeking though
Documentation i found this at: https://docs.unity3d.com/ScriptReference/ParticleSystem.GetParticles.html
private ParticleSystem.Particle[] m_Particles;
public ParticleSystem m_System;
public Transform target;
private Vector3 targetDir;
private void Start()
{
InitializeIfNeeded();
m_Particles = new ParticleSystem.Particle[m_System.main.maxParticles];
}
private void FixedUpdate()
{
// GetParticles is allocation free because we reuse the m_Particles buffer between updates
int numParticlesAlive = m_System.GetParticles(m_Particles);
// Change only the particles that are alive
for (int i = 0; i < numParticlesAlive; i++)
{
//obtain the inverse direction of each particle and apply velocity towards the object
targetDir = m_Particles[i].position - target.transform.position;
m_Particles[i].velocity += gravity * Time.fixedDeltaTime;
}
// Apply the particle changes to the particle system
m_System.SetParticles(m_Particles, numParticlesAlive);
}
private void InitializeIfNeeded()
{
if (m_System == null)
m_System = GetComponent<ParticleSystem>();
if (m_Particles == null || m_Particles.Length < m_System.main.maxParticles)
m_Particles = new ParticleSystem.Particle[m_System.main.maxParticles];
}
You aren't even using targetDir, why do you assign it? gravity isn't assigned either ... the code is more or less useless
Answer by richardkettlewell · Nov 28, 2017 at 10:59 PM
You could use the External Forces module and a directional wind zone component.
Your answer

Follow this Question
Related Questions
How can I change the gravity modifier of a particle system through script? 1 Answer
Custom particle system preview. 0 Answers
How can I apply gravity to each particle within a 'Gravity Zone' region? 0 Answers
How to make orbital gravity 1 Answer
Make a particle system with particles that stick to everything once they collide 0 Answers