0

Ok, after 10 hours of digging, I've come to the conclusion XNA really doesn't offer good collision support. Here is my problem.. imagine an apartment building in your game world. Wrap it with a bounding box.. rotate it on the Y axis 45 degrees. Now walk around it. If your camera intersects that bounding box.. you cant walk.. Well.. 50% of the bounding box is incorrect, because the box is axis oriented.. Now, use a sphere. A sphere that large, has ALOT of error.. I guess the question is.. how can I make collision detection with the building, that is rotated.. so I can walk around the building and staying just on the outside of the walls? There is the option of creating 2x triangles per wall, and doing some sort of collision detection there. You could fill the whole wall up with very small collision boxes(seems like a waste). Im really not sure, but after 10 hours of trying to find a good solution, im out of ideas.

Any help is appreciated, thanks.

indyz2
  • 1
  • If an AABB is good, and the only problem is that the thing is rotated so that it's not axis aligned, you can use an OBB, an oriented bounding box. The associated intersection routine is significantly more complex, but it's perfectly doable. –  Dec 30 '13 at 22:32
  • My environment already has OBB around the objects. Unfortunately, XNA converts them to ABB. Do you have links, or suggestions to what kind of collision testing to do on OBB? Ray, Triangle, Sphere, etc? – indyz2 Dec 30 '13 at 22:45
  • ... XNA converts them to AABBs? I'm afraid I don't follow. An oriented bounding box is like an AABB, but freely rotated rather than constrained to the axes. It's a particular kind of bounding volume, like a sphere or an AABB or a triangle mesh. –  Dec 30 '13 at 23:06
  • i have all my points in an OBB.. I can rotate the points, etc. If you use XNA's Boundingbox.CreateFromPoints(pintslist[]).. then it creates an axis aligned bounding box.. so.. it converts it. – indyz2 Dec 30 '13 at 23:13
  • Im just need some collision for walking against a 45 degree wall. All other boxes can be AABB for bullet collision, etc. – indyz2 Dec 30 '13 at 23:15
  • Well of course an AABB class (that's what `BoundingBox` is, despite the slightly generic name) will create an AABB, regardless of what points you ask it to bound. You clearly need something different for this case, as `BoundingBox` is and will remain a AABB and your case doesn't fit AABBs. –  Dec 30 '13 at 23:23
  • I think the best solution will be to use a ray intersect, against a triangle mesh. Converting the OBB to 8 triangles, to take care of the sides. Wont be able to try for a couple days though. Ill give an update then. – indyz2 Dec 31 '13 at 00:38
  • ok.. So here is what I come up with.. need to find the distance from the ray.. to the intersect point. Then find if that point is within the triangle. SO I used ray.intersect(plane) . That seems to return a number that is NOT the distance from the origin, to the point of intersection... So.. I found ALOT of code, and tried it. I have not found an example that... takes a ray.. checks to see if it intersects the plane, get the exact point of intersection. Make sure the triangle is CCW, make sure the point is in the triangle. – indyz2 Jan 02 '14 at 22:39
  • I found this But it always returns false because it reads the triangle is not CCW...'vector V0 = P0 - P vector V1 = P1 - P vector V2 = P2 - P vector V01 = V0 X V1 vector V12 = V1 X V2 vector V20 = V2 X V0 float s01 = V01 dot D float s12 = V12 dot D float s20 = v20 dot D if ((s01 >= 0) || (s12 >= 0) || (s20 >= 0)) return vector NORMAL = normalize ((P1 - P0) X (P2 - P0)) float DISTANCE= -(P0 dot NORMAL) float DEN = NORMAL dot D if (DEN == 0) return float T = -((NORMAL dot P) + DISTANCE) / DEN // Intersection point is P + T * D – indyz2 Jan 02 '14 at 22:52

0 Answers0