flipping a sprite around

I am brand new to unity and following a few tutorials online.

I am just following a tutorial regarding movement and have made a script to move the player left and right when pressing A and D. The sprite I am using (a downloaded santa character) I have noticed doesnt seem to be dead centre in the frame. The code I have used flips the sprite on the x axis when I change direction

transform.localScale = new Vector2(-1, 1);

and flips it back again when I move back to the left. The character though when flipped to face left, actually moves a little further to the right. This causes an issue if he turns when very close to a ledge as he flips and then gets stuck as his collider is within the ledge collider.

The sprite I downloaded has about 70 frames to allow some animation for running jumping etc. I have had a look at the sprite editor and it seems to allow me to change the ‘border’ around the sprite, but this doesn’t seem to carry through when I set my sprite as the sprite I have amended…

Could anyone help on how I can overcome this? I have attached a couple of images.

Thanks
Danny


6601363--750670--Screenshot 2020-12-08 at 17.29.45.png
6601363--750673--Screenshot 2020-12-08 at 17.31.29.png

change pivot point on sprite import settings

1 Like