How do games like Octopath Traveler handle the angle of shadows, and is this even possible in Unity? [URP]

So it’s been quite a while since I made this, but I managed to come to a workable solution to this issue that I thought would be worth posting in case anyone stumbled upon this topic. Basically, rather than simply rotating 2D objects to face the camera, I wrote a script to apply a custom projection matrix to the camera, that makes everything on the Y axis face the camera perfectly, as can be seen here:


I came to this solution after eventually finding this article. The projection matrix script is linked at the bottom of the article, but I had to change some stuff to get it to work. Here’s the relevant bit I had to change:

    private void OnPreCull()
    {
        // First calculate the regular worldToCameraMatrix.
        // Start with transform.worldToLocalMatrix.

        var m = GetComponent<Camera>().transform.worldToLocalMatrix;
        // Then, since Unity uses OpenGL's view matrix conventions
        // we have to flip the z-value.
        m.SetRow(2, -m.GetRow(2));

        // Now for the custom projection.
        // Set the world's up vector to always align with the camera's up vector.
        // Add a small amount of the original up vector to
        // ensure the matrix will be invertible.
        // Try changing the vector to see what other projections you can get.
        m.SetColumn(1, 1e-3f * m.GetColumn(1) + up);

        GetComponent<Camera>().worldToCameraMatrix = m;
    }

I admittedly don’t know why it works this way, but I had to change the script to set column 1 instead of column 2. This solution of course has now come with another set of issues (URP shadows aren’t working correctly, moving up on the Y axis causes objects to appear to move backwards,) but I think that it might be beyond the original scope of this topic.

You're an absolute goat for posting the solution after 8 months thanks a lot man!