- Home /
Make Shuriken Particle System lock on to a target
Hi! I'm back with another issue that's really puzzling me.
I have a Fireball particle effect made with shuriken and it is awesome. The only downside is that the effect travel on a straight line. So I attached a script on the particle system that will handle the rotation, curvature and velocity in general.
What I do is: 1. Get the particles in the system 2. Cycle through the particles and adjust the velocity 3. Reassign particles to the system
That seems pretty obvious to me. Now, since I want the particle effect and trails to lock on to a target, I add a steering force to every particle in the system. Sadly, this doesn't produce the expected result. Instead the particles drift away from the target, like if a magnetic field was around the target and the particles were made of pure iron.
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particleSystem.particleCount];
particleSystem.GetParticles(particles);
for(int i = 0; i < particles.Length; i++)
{
Vector3 dir = target - particles[i].position;
dir.Normalize();
particles[i].velocity += dir * Time.deltaTime * 10;
}
particleSystem.SetParticles(particles, particles.Length);
I'm surely missing something obvious here, but my brain refuses to work and I can't get this to work.
taking a guess, could it be b/c you are adding to the already existing velocity ins$$anonymous$$d of defining it?
Also, I would throw this into fixed update and get rid of the time.deltatime. Try something like this in fixed updtae.
particles[i].velocity = dir * speed;
I am guessing that the particle system is applying a force that you do not want. $$anonymous$$ake sure your particle system does not apply any force over time.
If you want a more gradual thing, you could say the current particle's velocity transitions to dir over time Vector3.$$anonymous$$oveTowards( current velocity , wanted velocity, smoothness);
What do you think?
Actually i figured it out (kinda): it was because the simulation space was set to local ins$$anonymous$$d of world (even though i was sure that i switched it to world, but whatever) :D it needs a lot of adjustement because the fireball shoots over the target and then come back, starting an orbit movement. But I suppose I'll just check for the distance with the target and adjust the force accordingly :D
Thanks anyway for the tips, I'm going to move everything into fixed update, it makes more sense :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613172022im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Water physics in solid object 2 Answers
How to make particles react to movement of particle system 4 Answers
Add collision planes to Shuriken ParticleSystem prefabs 1 Answer
Particles seem to be "masked" by geometry 0 Answers
Separate particle systems rendered together with a single sorting mode? 0 Answers