Support Forum

Rotating game object in 2D top down

Just starting using this package for pathing in my top down 2D game. Its not like an entirely top down view, kind of at an angle. I’m using the pathing for some enemies and I want them to flip the game object to point in the direction of their path.

I’m using an extended version of the AIPath script so I can add some custom logic. I played around with the “enable rotation” feature but it seems like this kind of treats the object as like rotation in 360 degrees. These objects have rigid bodies, so I tried locking them on the z axis but that just prevents any rotation at all.

What I have currently just flips the local scale based on the desiredVelocity from the AIPath script.

        
        if (desiredVelocity.x >= .01f)
        {
            transform.localScale = new Vector3(1, 1f, 1f);
        }
        
        if (desiredVelocity.x <= -.01f)
        {
            transform.localScale = new Vector3(-1, 1f, 1f);
        }

My solution above achieves what I want, but ideally if there was a way to just configure the script to do this for me then it would be preferred.

Is there a setting im missing here? For context, this is most of my config

Hi

The built-in movement scripts only have support for changing the direction by rotating, not by flipping the object. So I think a custom solution is the way to go here.

1 Like