Home > Uncategorized > BModel Collision

BModel Collision

Rotating bmodel collision is quite tricksy!

I got stuck on this one for many hours, and ended up trying a bunch of different ways.  As I keep an inverted model matrix around, I figured the best way would be to transform the ray into modelspace and do the collisions from there.  That’s a start, but I ended up having my player’s box poke way into the side vs some rotations.  It was never consistent.

A simple door tilted in X a bit

The above bmodel is a simple box, tilted a bit, and if I squeezed under it and collided with the edge, I’d have to poke really far in to actually collide with anything.

I realized that the player collision box doesn’t properly rotate when the endpoints of the ray are transformed into model space.  I decided to grab the box corners, transform those into model space (which would be properly rotated), and then take the axial extents of that.  Doing that and drawing it gets you this (though my collision box is messed up, but you can see the general shape):

 

It’s poking in!  And the initial boundary overlap tests succeed, but I still get no collision down in the bsp traversal.

After a lot of frustration and drawing boxes and rays, It eventually dawned on me that my player’s bounding box is not centered!  I use a 16 width by 56 height box centered at the feet.  This was my problem, as the transform into model space often made the box oddly off by a bit that I couldn’t explain.  It was at it’s worst when the bmodel was upside down.  I could walk entirely by on the bottom.

So the basic algorithm I’m using is:

  • Transform player boundbox corners into model space
  • Axial bound the corners to form a good modelspace bounds
  • Recenter the new box on the origin
  • Transform ray into model space
  • Sweep the box through the model bsp as normal

Now I can collide with models at any arbitrary rotation.  Next step is to enable moving the models with collision.

Categories: Uncategorized Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment