Nerd For Tech
Published in

Nerd For Tech

Flipping the Hitbox in Unity

When I was creating the hitbox I had my player facing the right. when I turned the player to the left, all the sprites would flip but the hitbox would not.

This would mean that my attack would not work correctly when the player is facing the left.

To flip my sprites I was using .flipY and .flipX.

This method would not work for the hitbox so I needed something else. After a short time, I came across a way to flip the hitbox and all the other sprites.

This method was to change the local scale of the parent object to -1 when the player is going left and 1 when the player is going right. This gave me the result I was looking for and eliminated the need for that big chunk of code to flip the sprites.

This code did exactly what I wanted it to do.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store