Flip sprite from origin point to stay centered with hitbox (SOLVED)

Greetings everyone,
In my game, I want to position a collision box onto my character for more precise and realistic collisions with the environment, so I went and positioned a hitbox to my player, and it works pretty well.

That is until my character flips around…

My character kind of has a wider sprite, but his center is not in the exact center of the sprite, so I moved it to the middle of his body rather than the middle of the whole sprite.

However, whenever my character flips the other way, he slightly clips out of his own collision box.

So basically, I need help making the sprite so that the sprite flips from the origin rather than just flipping the whole thing. Here is mock up art of what I’m trying to explain:

Any help is appreciated. Thanks in advance ^^

1 Like

I have been there :slightly_smiling_face:

Assuming you are not using any extra custom points (x,y) to positionate the sprite over the hitbox, put the origin X coordinate of the HITBOX at its center.

That should work.

if you have two sprite one for hitbox and other with the player animations, you could check if player is flipped then correct the postition by add/substract to X.
if obj_player is Flipped
– set position to obj_player.x = obj_hitbox.x()+16
or
– set position to obj_player.x = obj_hitbox.x()-16
hope this helps.

1 Like

Thanks, I fiddled around with this until eventually I got it to work the way I wanted it to ^^