Search Unity

Question Stopping particles at distance

Discussion in 'Visual Effect Graph' started by RogueCode, Jan 20, 2021.

  1. RogueCode

    RogueCode

    Joined:
    Apr 3, 2013
    Posts:
    230
    I'm using VFX Graph to make bullet tracers. To do this I'm spawning a burst of 1, and calling .Play() whenever I want one:
    upload_2021-1-20_17-40-29.png

    However I'm not sure what the best way of making them stop when they hit something is. Let's say I shoot at a wall, I need the tracer to not go through the wall. I know how far that is obviously - is there maybe some way I can set a max distance before getting killed (or hidden) per particle?

    I imagine this will get trickier once I need to be able to spawn multiple tracers in a single frame with different distances, but for now just one per frame is ok.

    Thanks!
     
    rduclos56 likes this.
  2. rduclos56

    rduclos56

    Joined:
    Jan 13, 2015
    Posts:
    6
    I have the exact same need, there's unfortunately not a lot out there on this approach for VFX Graphs yet.. Or if we should even be using VFX Graphs in this capacity?

    Here's what I've found so far, this guy https://www.raywenderlich.com/9261156-introduction-to-the-visual-effect-graph#toc-anchor-001 Check out the section "Controlling the particle movement" the author indicates. Your "tower position" or end position I would think would be a position on your wall that the bullet was fired toward.

    I couldn't get that to work but maybe you'll have better luck.

    One takeaway from that though was the LERP function, which makes me think we have to LERP the particle's position to the target destination and "set alive to false' once it reaches that destination or somehow set the lifetime/age of the particle to equal the time/distance for the LERP function to execute.

    ^That's all theory and I have tried some things and haven't gotten anything salvageable. I'll update you if I find a solution to this.