1
\$\begingroup\$

I am new to XNA and I am having problems with collision detection when I rotate my sword. I am using a rectangle bounding box approach and I don't know how I can rotate my rectangle together with the sword sprite.

http://picpaste.com/pics/f10268c108e885498a4ae603ab030a60.1328941784.png

Any suggestions on how can i solve my problem is really appreciated. Thanks!

\$\endgroup\$
1

2 Answers 2

2
\$\begingroup\$

I believe this article will be of some help to you. It has sample code that will show you how to rotate the points on a rectangle but also show you how to use the separating axis theorem to detect collisions on a rotated shape (in this case your collision box). On a side note, the web site is also a great resource for learning XNA.

http://www.xnadevelopment.com/tutorials/rotatedrectanglecollisions/rotatedrectanglecollisions.shtml

One other solution might be to use a few points (instead of rectangles) that change when the animation changes. Then use those points to detect collisions. I've heard of storing these points alongside animation frame data in an .xml file. Might make for a simpler approach than using the separating axis theorem. Hope this helps. Good luck.

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

use a bounding circle instead with the 0-90 degree angle being the distance you can slash vertically for example.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.