Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Drawing smooth weapon slashes

Discussion in 'Visual Effect Graph' started by chemicalcrux, Apr 6, 2023.

  1. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    I'm adding sweeping visual effects to the swords in my game. I'm using ribbons, and they work pretty well -- but for very fast animations, they get very jerky.

    I figure I could fix this with the power of splines. I've grabbed the
    com.unity.splines
    package, and I can create nice smooth paths from the fast swings -- but I'm stuck on the part where I turn that into a visual effect!

    I'm going to have to generate several particles per frame and provide the position for each one. I think I'm just going to add four Vector3 parameters to the visual effect and store four positions in those...but that doesn't feel very scalable. If I want to smooth further (maybe adding a variable number of points depending on speed), I'll have to add even more parameters!

    Any thoughts on how to make this simpler?
     
  2. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    Some updates: I'm having trouble drawing several particles per update. I tried setting a Vector3 property and using that as the position in the "Initialize Particle Strip" block:

    upload_2023-4-6_17-49-48.png

    (I'm a little confused as to why I can't just use Set Position, but I guess it's because it needs to set the position at the correct index?)

    It works normally if I rig it up like this:

    upload_2023-4-6_17-50-53.png

    ...but if I try to hook it up to an event that I call several times per update, I get nothing at all.

    upload_2023-4-6_17-51-9.png

    Maybe I'm just completely misusing things here?
     
  3. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    Okay, one last post for the moment -- I found this thread, and I successfully got it working with individual particles.

    I send an event several times per frame, with a different position value attached each time. That winds up creating several particles in several different places simultaneously!

    I cannot, however, work out how to do the same thing for a particle strip.
     
  4. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    128
    Could you share a small package so that I can help you with the strip Setup?
     
  5. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    Thanks! I actually got the strip positions working -- I'm a little unclear on what was wrong, exactly; I think I was misunderstanding how to use Direct Link. Here's how it's looking now...

    upload_2023-4-7_9-1-59.png

    I'm just working on the orientation now. I need to get it to line up with the long axis of the sword. I'm unclear on how to do this: I'm guessing I need to include an orientation with each event, but I do not know how to do that!

    I attached a package with a demo of how it's behaving. There's some cruft (i can't remember why i decided to name an attribute "blorp"), but it should be straightforward enough :p

    I tested it in 2022.2.9f1 using the HDRP. The "Line" prefab will spawn an object called "Line's Target" and then draw particles based on the target's position.

    I did it that way so that the spline gizmos would line up correctly; leaving it on the weapon meant that it would fly all over the place.

    Note that it didn't work on the first try...but it started working after I open the picker for the shader on the "Output Particle Quad" node. It might've just been a coincidence! Just something to try if it's misbehaving :)

    So, in short, my original problem seems to be fixed, but I'd appreciate some pointers with the orientation (and for Direct Link in general!)
     

    Attached Files:

  6. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    128
    Thanks for your package, it helps me to see where you wanted to go.
    I'm not an expert with Direct link as I didn't use it that much, but I can help you on the orientation part.

    What you often need to orient a particle or a Strip in general is two vectors
    A "Facing" vector that tell which vector my particle plane should "face" and an Alignment Vector.
    In which direction the Particle/strip are aligned to. With this two vectors, you can calculate the Third one by doing a cross product between the two previous.

    Now VFX Graph provide an "Orient" block that can help you with this task and more infos are present on this page:

    Here are two examples for "custom" particles orientation:
    Unity_DdXOUqrNGs.gif
    Above, you can see an example of particles that are always "Facing" the camera, but their alignment is blending between the "Normals" vectors of the Origin Sphere and a (0,1,0) up vector.
    upload_2023-4-11_15-0-17.png
    Two setup for "custom" particles orientation.

    So regarding your setup, you'll have to pass two vectors to "Orient" your strip.

    For this, base on your script, I just added two other attributes in the event:
    axisX, and axisY:

    Code (CSharp):
    1. attr.SetVector3(id, pos);
    2. attr.SetVector3("axisY", up);
    3. attr.SetVector3("axisX", tan);
    4. vfx.SendEvent("Draw", attr);
    To define the values, I've been using the "Evaluate" method of the Spline package that lets you compute the interpolated "position", "direction" and "upDirection" at ratio t:
    Code (CSharp):
    1. spline.Spline.Evaluate(t, out pos, out var tan, out var up);
    Now in VFX Graph the only thing that you needs to do is to "inherit" those attributes like you did for the position.
    upload_2023-4-11_15-10-45.png


    And use them in an "Orient Block":
    upload_2023-4-11_15-11-19.png

    This Should give you a correct Orientation:
    upload_2023-4-11_15-12-39.png

    Hope that this post will be helpful. Have a great day.
     
  7. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    Got it! That makes a lot of sense, thank you -- I was pretty fuzzy on how the orientation worked, and I think I see what's going on now :)
     
    OrsonFavrel likes this.
  8. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    128
    Glad to know that it make more sense.;)
    Please don't hesitate to share your results. We all love nice VFX trails :)