- Home /
How to flip hitboxes if my 2D Sprite is Flipped in AnimationsEditor ? [Unity2D]
Hello Unity Community ! First of all, note that I looked around the net to find some solutions to my problem before posting here, which wasn't a success xD. I will try to be as clear as possible. I'm working on a 2D Platformer since a while. In my code, atm, when I click with my mouse, my 2D Sprite character will attack. And today, I decided to create the sword hitboxes.
I basically created 3 childs GameObjects under my character's GameObject called SwordHitBox1 / 2 / 3, which have polygonColliders2D set as Triggers, each edited in coordination to their sword attack animation frames (I switch those hitboxes GO's to Active / Unactive when desired in the animation editor). Associated with an OnTriggerEnter2D in my character script, everything works pretty good !
BUT, these hitboxes work when my character is facing right. I mean, they are designed for my character when he's facing right. Designing those for when my character is facing left is not the problem, the problem is that I don't understand how I'm supposed to tell the animation editor WHEN my character sprite is flipped or not. If I could implement an (if character.flipX() == true) in the animation editor, THEN I could design the hitboxes for my character when he's facing the left.
Cause yeah, note that I used the SpriteRenderer.flipX() method in my character script to flip my character sprite whenever the player decides to walk to the right or the left.
I hope that it makes sense, and I'm really looking forward to any source of help. Thanks for reading !
Answer by Midane53 · Sep 27, 2017 at 09:26 PM
Okay for anybody having the problem, I found a solution.
I designed the hitboxes for when the enemy is facing the left, and then I deleted the left facing sword attack animation, and create a new one which is an other right facing sword attack animation, with the left facing sword attack animation hitboxes designs. It's a bit messy, but it works.
I still wonder why Unity couldn't just flip when character when playing an animation facing another direction.