0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Anko Jun 4 '14 at 11:58
  • \$\begingroup\$ 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 \$\endgroup\$ – Jetbuster Jun 5 '14 at 3:17
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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));
        Matrix rotate = Matrix.CreateRotationZ(currentAngleInRadiens - previousAngleInRadiens);

        forEachPoint
        {
            if (pointHasMoved)
            {
                //Move the point to a center position(this is for rotating the point around a relevant position)
                //Move the point back to its original position
                point = Vector2.Transform(point - centerPoint, rotate) + centerPoint;
                // Translate the point
                point = Vector2.Transform(point, move);
            }
        }
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.