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 Rotate object to world forward direction?

Discussion in 'Shader Graph' started by SuperFranTV, Sep 9, 2023.

  1. SuperFranTV

    SuperFranTV

    Joined:
    Oct 18, 2015
    Posts:
    140
    Hi,

    i would like to rotate my object to worlds forward direction.
    But how can i archive this in shader graph with vertex position?

    Taking the position node in object space + rotate about axis, but how to get world forward rotation?

    i think others need this information too.

    Edit:

    there is 1 problem, my character is rotating using its parent and the child objects has this shader, when the character moves back and forward all looks fine, but sideways the character gets bigger scale from this shader.


    thanks for all.
     
    Last edited: Sep 9, 2023
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    Might I ask why you are doing this in a shader instead of C#?
    Rotating/scaling an object in C# is very easy and performant
     
  3. SuperFranTV

    SuperFranTV

    Joined:
    Oct 18, 2015
    Posts:
    140
    It was the best variant that I could test to achieve the goal for my project.
    My project is in 2D, top-down, the quads are rotated 30 degrees on the X axis and look at a camera with X45 degrees. Instead of sprites I use 3D quads (optical reason). It's about the character he can move in 8 directions, the parent object is rotated in the direction of movement, the body parts are modular, they rotate in the same direction as the parent but the textures should still point towards the world forward axis and the 30 degrees tilted, that would be the goal.

    The alternative in C# is setting, the forward axis of each child to Vector3.forward, but how can i also rotate 30 degreese like when i rotate the parent 30 degrees at x-axis?

    EDIT:
    i got the half of the goal, the character rotates in movement direction but the sprites/textures looking to world forward, now i need the 30 degrees as the total axis of all childs, like when i'm rotating the parent (but i can't rotate the parent, this breaks the animations optic)
     
    Last edited: Sep 9, 2023