Search Unity

Instantiate 'splash' particle system OnCollisionEnter2D

Discussion in '2D' started by rboerdijk, May 10, 2020.

  1. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    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:
    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...

    Code (CSharp):
    1. private void OnCollisionEnter2D(Collision2D collision)
    2. {
    3.   var rot = Quaternion.Euler(90, 0, 0); // try hardcoded angle in x/y/z to see if anything happens
    4.   //Quaternion rot = Quaternion.FromToRotation(Vector3.up, collision.contacts[0].normal);
    5.   GameObject psys = Instantiate(bulletsplash, transform.position, rot);
    6.   ...
    7. }
    Any ideas anyone?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    So this is a particle system question really. I'll add the particles tag so a particle dev can see it.
     
    rboerdijk and karl_jones like this.
  3. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    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.
     
    MelvMay and rboerdijk like this.
  4. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    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 ^^) :
     
    MelvMay and richardkettlewell like this.