Search Unity

Question Rotate particles towards direction from shape

Discussion in 'Visual Effect Graph' started by Qriva, Oct 22, 2022.

  1. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    I always struggle to manipulate angles based on vectors in VFX graph. I have the following problem:
    upload_2022-10-22_13-39-41.png
    There is spawn position from shape - box in this case and I want to spawn particles with the angle pointing towards direction generated by this block. For the picture above it will be just box normal, however there are no tools to do that or I am just missing something abvious.

    I can't do something like this as it causes error
    upload_2022-10-22_13-43-24.png
    I could do it in other way with point rotation map or something like that, but that is not the point. Can it be done easy way? By the way I don't want them to just point fixed direction, but be affected by angular rotation over time.
     
  2. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    191
    Morning @Qriva .
    I'm not sure that I understand fully how you want to orient your Particles/Particles Mesh.
    So If my answer is off, don't hesitate to correct me.
    Usually , for "Facing" and "Alignment" I use the "Orient" block .
    Several mode exist and I think that from what I understand you might want to take a look at "Look At Position" Mode.
    Here's my setup :

    upload_2022-10-24_9-49-21.png

    Unity_virCYrzq4I.gif

    Exception while compiling expression graph: System.InvalidOperationException: The expression UnityEditor.VFX.VFXExpressionExtractAnglesFromMatrix is not valid as it have the invalid flag: InvalidOnGPU, PerElement



    Regarding this Error, could you tell me in what block and context did you plug your "Lookat" block so that I can share with the Devs .

    I hope this help
     
    Last edited: Oct 24, 2022
    STAndreiBelov likes this.
  3. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    191
    So regarding the Error that you have. At the moment it appears that we can't extract the "Angle's information" from a Matrix on the GPU. You can get the "Position" and "Scale" but not the "Angle".
    In case you need more in-depth infos on the "Why can't we ?!!!", I will ping my colleague @PaulDemeulenaere.

    Have a great day.
     
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    Huh, quite dumb from my side. You are correct, orient changes space of particle and then angles are applied.
    However I am not sure I can do exactly what I need as look at position uses camera position and moving camera is going to rotate particles (btw system must be world space) . I can try advanced mode, but can't test it properly right now, so I am going to check it when I am back home.

    On the side note, is that actually expected that direction is generated in local space even if system is in world space?
     
  5. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    191
    If you don't want the Camera to rotate your particles, "Advanced Mode" should be your best bet.
    Be aware thought that the "Orient Block" code don't have a safety net or a "Fallback vector" in case, the cross product operation is null.
    So in the Case of a Box location. Your "Top" and "Bottom" Direction will have issue with the Cross-product operation of the "Orient Block".
    Here's the code for the "Orient Block" in Advanced:

    axisZ = normalize(AxisZ);
    axisX = normalize(cross(AxisY, AxisZ));
    axisY = cross(axisZ, axisX);

    upload_2022-10-24_12-38-24.png
    upload_2022-10-24_12-37-46.png

    So what you can do is some logic to change the "Y" Axis" based on the "Box" Normals/ Direction Attribute.
    To be honest it's pretty ugly... We should work/update the "Orient Block" so that orienting Particles is more straightforward for the user.

    upload_2022-10-24_12-41-0.png
    Unity_NQns58dFqN.gif
    Unity_QCLLJmyIaC.gif
     
    Qriva likes this.
  6. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    191
    Regarding your Side Note, I'll check with the Devs as I'm guessing here...
    I would say that while the system is in "World Space" it doesn't change by default the "Space" of the "Direction" that is written by the "Shape Block".
    But I guess that if you change the "Space" of the Shape to "World" you should obtain your "Direction" attribute in "WorldSpace".

    upload_2022-10-24_12-50-25.png

    Will come back , If my guessing was wrong.
     
  7. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    191
    Sorry I was wrong.
    The "Space" of the Shape indicate in which Space we input the "Shape Values", in this case "Center" . Those inputted Values are then converted to the "System" Space.

    And the "Position/Direction" attributes written by the Block should be in the System Space.
    Again, sorry about my post above, my assumptions were wrong.
     
  8. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    No problem, actually I know it's space of box itself, but as you said if this supposed to generate values in system space, then I think it produces wrong values.