Monday 21 May 2012

3D Mesh Collision!

I've come back to Tunnel Flyer now that the controls work. I added randomly generated tunnels using small segments (simple ones for now). Currently I am working on the collision detection between the player's ship and the tunnel walls. I can't see a nice way of using primitives to detect the collisions so I figure this is a good time to learn how to use the model geometry for collision detection.

What I have so far is: when a player is close enough a segment, it checks how far the player is from each triangle in the model. Given that the models are rather simple I was hoping it wouldn't be too intense. I didn't want to attempt optimizing too early on but right off the bat I'm at what looks like ~10 frames per second! I'll need to make improvements to when I do the checking and maybe spread it across a few frames.

The collision detection itself is an algorithm I got from a book I'm still reading; "Real-Time Collision Detection" by Christer Ericson. Before I even consider improving that (which I'm sure they little to nothing I could do) I'm going to fix the code around it first. Hopefully by the end of the week I'll have the collision detection working correctly and I can see to what limit I can push it.

No comments:

Post a Comment