Debugging Particle Collisions & Lifetime (Realm Rush)

Hi folks,

I just finished the Realm Rush unit, with everything working fine. Woohoo!

At some point though, it looks like my ballista projectiles stopped registering hits on the rams even though they were working before. It was strange since I didn’t change anything about the collision logic, since it’d have been working before the pathfinding refactors in the lecture. I tried going through the debugging and it looks like OnParticleCollision simply wasn’t being called; after going through everything (yes, I have collisions sending messages on the particle, I do not have it set as a trigger), I found that changing “Lifetime Loss” from 1 to 0.95… seemed to restore OnParticleCollision events. Though now the particle acts a little jank for a fraction of a second as it tries to aim at a new target.

image

Anyone have any ideas what I might commonly be running into? Any toggles or flips I should hunt for, maybe I’m hitting something invisible in my scene, or…? Since I don’t know how to retrieve the name of what my particle is hitting, I am at a loss for what is causing my particle to end lifetime prematurely.

Hi Stepwise,

First of all, which version of Unity do you use? Maybe you are experiencing a bug in Unity.

Secondly, the OnParticleCollision method comes with a parameter. See here:

Via that parameter, you should theoretically be able to analyse the problem further, e.g. by logging the name of the game object into your console that had been hit by the particle.

If the particle collides with the wrong game objects, look up the layer-based collision matrix in the manual. Make sure to click the Physics (the Physics2D!) in the settings in your Unity Editor.

Did this help? :slight_smile:


See also:

Aw shoot, I thought I’d read the manual hard enough. :slight_smile:

OnParticleCollision on the ParticleSystem helped me debug - I was spawning the Ram prefabs at 0 on the y axis and they were centered; meaning the center of the prefab was sunken in the ground and the particles were all colliding with the tiles. Giving me tons of debug messages of (2,1), (2,2), et al!

Not sure where I went wrong in the tutorial, but I ended up just defining y manually on the CoordinatesToPosition() method and my towers no longer fire at the ground. Now I can chuck this project somewhere to look at later. :slight_smile:

Thank you very much!

Good job on solving the problem! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms