Jump to content
  • Advertisement
Sign in to follow this  
RogDX9

Horizontal Flip Custom HitBoxes With Sprite Flip in 2D Game

This topic is 1140 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello Everyone, 

 

I have Custom Hitboxes defined per sprite for enemies as std::vector<Rectangle> where each rectangle is relative coordinates to the sprite, when doing collision detection, i just translate those Rects coordinates to screen coordinates and check for colliding objects and it works fine when sprite is not flipped and its in the same shape when the hitboxes were defined for it, however, in some cases when the enemy gets behind the player character it flips horizontally to give the enemy the ability to attack the player as well, there is no vertical flipping, thus hitboxes positions are now invalid and will cause wrong collision detection, i'm trying to find an algorithm to flip hitboxes sort of mirroring them.

what is the easiest way to (not sure about the right term here) flip hitboxes to match same positions when the sprite gets flipped.

Thanks for help.

Share this post


Link to post
Share on other sites
Advertisement

Ok never mind, i figured it out, it was easier than i thought, i just needed to subtract distance from Rect.X to sprite canvas width.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!