Search Unity

Question Any Math Wizards? Theory to convert 3D rotation to this unique 2D skew/shear setup?

Discussion in 'General Graphics' started by Jamez0r, Jan 4, 2021.

  1. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    206
    Hi guys, I'm working on a "2D" project, but we just decided to make the switch from an orthographic camera to a perspective camera for numerous reasons (namely easier parallaxing). When building the environment in our scenes, our artist had been rotating sprites along all 3 dimensions (not just rotating along the Z-axis) to get them to look good, and add a bit of variety. The result of rotating the sprites in 3D is basically like "shearing/skewing" a 2D sprite.

    Now that we are using the perspective camera we can't be rotating sprites on the X or Y axis. It would be really good if we could have an option to skew/shear the sprites - it really helps with our map layout process.

    I found this twitter post showing a really cool setup where you create an empty gameobject, and place your sprite as a child, and then rotate the parent and the child, and then scale the parent, and it works just like a 2D shear!



    From this twitter post: https://twitter.com/MajorMcDoom/status/1231449419825831943

    So now on to the question - performing the skew/shear using the process in that twitter post is much more tedious than simply rotating the object in 3D space. What I'm hoping to do is create an editor window with a button that would convert the 3D rotation on the sprite gameobject into the required rotation and scale on the empty gameobject parent and the sprite such that it matches. So the artist on my team could continue rotating in 3D and then just press the button to convert it. I can handle all of the editor window stuff, but I don't have much experience with 3D rotation math - anyone have a clue as to if/how that could be done?

    Thanks a lot for any help! :D