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. Dismiss Notice

Question Set Position Shape: Circle won't orient to player

Discussion in 'Visual Effect Graph' started by enric_unity978, Aug 16, 2022.

  1. enric_unity978

    enric_unity978

    Joined:
    Mar 7, 2022
    Posts:
    8
    Hi, I have a VFX graph which spawns three particles: a smoke trail, some sparks and a smoke burst which is circle-shaped.

    upload_2022-8-16_16-46-47.png

    My problem is that the circle shaped burst does not align with the player's direction, it needs to be rotated. I can't seem to make it rotate by any means, I've tried setting the Z Axis, force-rotating it by hand just to see if it rotates... Currently I'm using a property which is binded to the character transform, but it doesn't work either.

    This is my Init block:

    upload_2022-8-16_16-46-23.png

    And this is my output node:

    upload_2022-8-16_16-47-15.png

    any ideas on how to accomplish this?
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    First you need to get position on circle, then you rotate that position. Vlad explained it here, but it's better to upgrade your Unity version to 2021.3 as there are builtin transforms into shape blocks.
     
    enric_unity978 likes this.
  3. enric_unity978

    enric_unity978

    Joined:
    Mar 7, 2022
    Posts:
    8
    Thanks for this reply but it doesn't seem to work for me: now the burst is accurately rotated, but the position is a total mismatch. Which makes no sense because I'm getting the current position, so it makes me really confused.

    Is there any other way to do this?
     
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    It must work, you did something wrong then. Check if spaces are correct. Can you show what actually happens and what should happen? Some screenshot + updated graph?
     
    enric_unity978 likes this.
  5. enric_unity978

    enric_unity978

    Joined:
    Mar 7, 2022
    Posts:
    8
    I will try to be as precise as I can.

    My target with this VFX is to create a sprint trail that has an aticipation consisting of some sparks and a smoke halo. This halo has to spawn at the local position but update at world position, so it stays in place.

    My first problem was this:

    upload_2022-8-17_12-11-33.jpeg

    I managed to get all working, but the halo itself wasn't rotated properly, it always looked at the camera.

    Using @VladVNeykov method for changing rotation i managed to make the halo rotate accordingly, but now the main problem is that the position of the halo becomes world space, not local space:

    upload_2022-8-17_12-13-51.png

    (sorry for the weird censorship, my team is kind of strict with privacy)

    This is the actual graph i am using for creating the halo:

    upload_2022-8-17_12-14-59.png
    upload_2022-8-17_12-15-29.png

    Updating the projewct is not an option because it affects other crucial game systems, and i've also tried to put this effect separated in another graph, in its own gameobject, and rotating it forcefully by code, but none of that worked for me.

    Thanks for your help and interest!
     
  6. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    The problem is that position outputed by circle becomes world space, so currently you use world position as local position in transform block, try changing spaces.
    upload_2022-8-17_13-38-27.png
     
    enric_unity978 likes this.
  7. enric_unity978

    enric_unity978

    Joined:
    Mar 7, 2022
    Posts:
    8
    Looked like a great attempt, still doesn't work. We're back on the first place.

    And it really makes me frustrated because, why in the world wouldn't it work? It makes complete sense, the position is well rotated but not in local space, hence converting it to local needs to work, right?

    I can't seem to find any workaround for this, not even force-rotating the gameobject makes it face where i want it to face it, its so irritating
     
    Last edited: Aug 17, 2022
  8. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    What actually happens, it's still the same?
    If you can't solve this complex effect then break it into smaller pieces.
    Create new empty effect with single circle of particles and make it spawn where you want in local space with correct rotation and then make it work in world space.
     
    enric_unity978 likes this.
  9. enric_unity978

    enric_unity978

    Joined:
    Mar 7, 2022
    Posts:
    8
    I tried it and it seems that rotating the gameobject forcefully by code doesn't work either. Seems like the circle shape always faces the camera, without taking te GO's rotation into account.

    I'm trully about to give up on this right now!
     
  10. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    You are setting it in Initialize, so if the GO's rotation is changing after the particles have spawned, it would not update. You can try moving your position logic in your Output.

    If that doesn't fix it, I can take a closer look if you can share a small package with your setup.
     
    enric_unity978 likes this.
  11. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    My bad, I didn't take into account that object rotation is already accounted in local Tranfsorm, so it gives weird results as ring is rotated around object rotation, but with additional tilt. Instead we can use world space to do math, then use Vector3 to lose space information, so we can connect it as local space. I attached example graph - is it what you need?
    upload_2022-8-18_21-49-18.png


    @VladVNeykov There is some nasty bug when using Local To World node.
    upload_2022-8-18_21-47-40.png
    I added additional inline Transform, because I was very confused what happens - might be not needed.
    You can reproduce like this: Connect LocalToWorld to Transform with some position and save. If you remove connection from LtW or change space of (0,0,1) position and then change again you might notice that after saving you get different results for the same setup. That was tested on version 2020.3.19, but I managed to reproduce this on 2021.3.1 with setup exactly the same as above (but it was harder). Also at first the L/W of inline Transform was disabled and changed after connecting, but later it broke and I could change them what probably caused this error:
    I think it might be related to the fact I added World To Local to the first block (Built-In Properties).
     

    Attached Files:

    enric_unity978 likes this.
  12. enric_unity978

    enric_unity978

    Joined:
    Mar 7, 2022
    Posts:
    8
    Thank you both for your interest and sorry for the delayed answer (i think our timezones are somewhat different). I really apreciate this.

    I've prepared a package with a simple scene using the effect. Instructions are displayed in the scene. I'll attatch it down below. I also provide this link, which is the same project as a ZIP file, so you don't have to set up the pipeline (plug and play version).

    As shown here, this is my initial problem:



    It doesn't matter which direction the player has, the ring position will always face the camera, while my intentions are for it to face the same direction (forward) as the player.

    But your method (@VladVNeykov) hasn't worked for me, and @Qriva 's solutions seemed just right but i couldn't make it work either. It does, however, change the rotation of the shape to its desired target, nontheless the position changes drastically:



    Last @Qriva 's solution doesn't work either, it makes some strange artifacts with the position, almost seems like it's setting it somewhere far in world space:




    Again, thank you for your suppor and involvement, this community is amazing!
     

    Attached Files:

    Last edited: Aug 19, 2022
  13. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    Not at home right now, but I tried my last method and it worked.
    I forgot one thing, it's there when you open graph, but it's not on my screenshot - Position Circle must be in world space too. Additional note - the Offset Angle is not object angle, but your own custom rotation for circle.
     
    enric_unity978 likes this.
  14. enric_unity978

    enric_unity978

    Joined:
    Mar 7, 2022
    Posts:
    8
    THIS WORKED FOR ME!! Setting the circle shape to world space set the rotation accuratelly where I wanted

    Nonetheless, the position remained in world space, so I had to create a property to set it right where I wanted, just as I did with the rotation.

    upload_2022-8-20_22-4-6.png
    upload_2022-8-20_22-5-4.png

    And now it does work just fine!!




    THANK YOU SO MUCH FOR YOUR SUPPORT!!
     
    Last edited: Aug 20, 2022
    VladVNeykov likes this.
  15. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    It should not be needed to pass rotation and position to the graph, the trick is to lose space information. In your graph you connected Transform directly to Set Position and it gets it as world space, meanwhile in my case I set it without inheriting the space and I set it as local (see my picture), so it will be automaticaly rotated. Also set circle origin to 0 instead of (0, 0.5, 0) or you might get unexpected shifts.
    Anyway, glad it finally worked :D