Instantiate 'splash' particle system OnCollisionEnter2D

Hello,
I’d like to have a ‘splash’ particle effect when a projectile hits a wall, but I’m having problems getting the alignment to work:
5829130--618076--psys-impact.png

I’d like the impact to align with the surface it hits (90 degrees right in the above screenshot). That will involve something with the normal of the contact, but as a first attempt to see that “something” is working trying with a hardcoded Euler angle - but that doesn’t seem to work.

I then tried pausing on impact, and modifying the rotation angles of the gameobject to which the particle system is added, but it doesn’t change the visible rotation of the particles either… which is really confusing because it works perfectly fine if I select a gameobject with a sprite and change the rotation values…

private void OnCollisionEnter2D(Collision2D collision)
{
  var rot = Quaternion.Euler(90, 0, 0); // try hardcoded angle in x/y/z to see if anything happens
  //Quaternion rot = Quaternion.FromToRotation(Vector3.up, collision.contacts[0].normal);
  GameObject psys = Instantiate(bulletsplash, transform.position, rot);
  ...
}

Any ideas anyone?

So this is a particle system question really. I’ll add the particles tag so a particle dev can see it.

2 Likes

Setting the transform of the gameobject containing the particle system ought to work just fine.

If the system has already emitted particles, those won’t be rotated if the system is simulating in world space. If that’s the case, be sure to rotate it before playing/simulating the particle system. (Or use local space if you don’t need world space)

The shape module also has a transform that you could try setting, but t really shouldnt matter - the game object rotation seems like it should work.

2 Likes

Created new default particle system, with an animated spritesheet, billboard-rendering, simulation space is “local”, change the emitter to box with a tiny volume (to respawn in the same spot). When playing the animation is facing “upward” (like in the screenshot in the first post), changing rotation x/y/z of the object doesn’t change anything (you can see the ‘axis’ debug-visualization rotate, but the animated spritesheet keeps doing the same thing - irrelevant of the rotation).

I found an option under “Renderer”, a bit below where you can set it to “billboard” which says “Render Alignment” which is set to “view” by default. Changing that one to local, and then rotating the gameobject seems give the expected result.

Will experiment a bit more, but in case anyone else runs into this (appologies for the coder-graphics ^^) :

2 Likes