- Home /
Question by
UnderWolf820 · Jan 12 at 04:03 PM ·
physics3dparticlesmathfmovetowards
Why isn't my script to move particles working?
Hello, I am making a game in unity and ran into a problem. I want to make particles burst out of a gameobject follow the player. I have made this script :
Transform player;
ParticleSystem ps;
void Start()
{
ps = GetComponent<ParticleSystem>();
player = GameObject.Find("AutoAssign").GetComponent<AutoAssign>().player.transform;
}
void Update()
{
{
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.particleCount];
ps.GetParticles(particles);
for (int i = 0; i < particles.Length; i++)
{
particles[i].position = Vector3.MoveTowards(particles[i].position, player.position, Time.deltaTime);
}
ps.SetParticles(particles, particles.Length);
}
}
The problem is the particles seem to just move in one direction, go through walls and fall of the edge of the map. Does anyone know why this is happening?
Comment