# How can I make an object's hitbox rotate with its texture?

In XNA, when you have a rectangular sprite that doesnt rotate, it's easy to get its four corners to make a hitbox. However, when you do a rotation, the points get moved and I assume there is some kind of math that I can use to aquire them.

I am using the four points to draw a rectangle that visually represents the hitboxes.

• In a data-sense, all you need for making a hitbox rotate is to set some rotation field on the game object. You can then derive the new box corners with trigonometry. Collision detection on an oriented bounding-box is a trickier than with axis-aligned bounding-boxes, but it's solveable with Separating Axis Theorem. Jun 4, 2014 at 11:58
• Right now im looking at rotating the points with a rotation matrix and using SAT for the collision. Ill give the implementation a go tomorrow Jun 5, 2014 at 3:17

You could do so that you have a rotation matrix with a translation. From there you can take a point and transform it into it´s cordinate system. then it becomes like a regular hitbox collision.

Wiki has a good article on how this works in the depth : WIKI

The same approach works for a "pixel" collision method to, just remember to transform the collision point rather than the object it´s colliding with. Lazy foo has a AWESOME article on how to do pixel collision. It should be fairly easy to transform that code into any language. Lazy foo

So after some research into Matrices with the head tutor of IT I understand how to rotate each of the points, its a bit buggy still but it will rotate on the spot in time with the sprite as well as move with it in straight lines.

Heres some XNA relevant pseudo code that explains it

        Matrix move = Matrix.CreateTranslation(new Vector3((currentPosition - previousPosition), 0));