Search Unity

How to Change Rotation of Individual Partical on Runtime

Discussion in 'Scripting' started by brkbkc, Apr 1, 2022.

  1. brkbkc

    brkbkc

    Joined:
    Jan 28, 2019
    Posts:
    36
    Hello, in game i develop, i use bow and arrows to hit other objects. I choosed the way of spawning new arrow as gameobject on bow and the launch it to the target with a velocity. It's working well but, in terms of performance issues i started to think doing this with particle system.
    I set particle system and i succeed to spawn arrows as particles rotated to the target object.
    The problem is, while "Simulation Space" set to world and Render Alignment set to local, if i launch multiple arrows, each arrow rotates locally at the same while they continue moving in their way. What can be a solution to this? Maybe some coding?
    Thanks
     
  2. ZBerm

    ZBerm

    Joined:
    Jan 12, 2017
    Posts:
    61
    Is there a reason you want Render Alignment set to local?
    Set the Render Mode to Stretched Billboard and see if you like the result.
     
  3. brkbkc

    brkbkc

    Joined:
    Jan 28, 2019
    Posts:
    36
    Didnt work. It streches the sprite (or i could not do it :) ).
     
  4. ZBerm

    ZBerm

    Joined:
    Jan 12, 2017
    Posts:
    61
    It stretched the sprite because by default Length scale is set to 2. Set it to 1 and you will not stretch the particle.

    upload_2022-4-3_0-25-59.png

    Doing this will in the best performant way have your particles:
    • always facing the camera
    • move in world space so the emitter can move around without dragging particles with it
    • always rotate the particle to face the direction of travel

    upload_2022-4-3_0-27-36.png

    This even works if you're applying some other movement to the arrows after they are emitted.

    upload_2022-4-3_0-37-7.png

    It sounds like this should fit your use case perfectly, if not, and you really want to rotate individual particles in code... well yes that is definitely possible. But using the Particle System the way it was intended will be more performant.

    Does this work for you?
     
  5. brkbkc

    brkbkc

    Joined:
    Jan 28, 2019
    Posts:
    36
    i could not succeed, and now i decided to change the sprite to a circle bullet. Thanks for your help.