So I still haven't spent any time on figuring out the art style. Tonight I worked on collision.
The level geometry I have is a triangle soup created from Maya. This isn't the easiest thing to check collisions against - and in fact I've never written collision detection routines, so I only had a little bit of idea of the problems I would run up against. I'm quite sure that making the environment out of OBBs would be simpler, but out of curiosity I left it as is so I could work through it and discover the problems myself.
What I had going yesterday was simple raycasting. Every frame, when the ship moves, I calculated a 'distance to move this frame', and casted a ray from the current position to my next desired position (based on my velocity vector) into the triangle soup and see if I hit any triangles. If I did, I would calculate the rebound effect. I did this recursively until the 'distance to move this frame' was zero. (This recursive processing handles the case when you run into a corner and end up bouncing off of 2 walls in 1 frame)
So I knew the raycasting was naive, and tonight tried to replaced it with casting a swept sphere instead of a simple ray. The idea here was to combat the precision issues I had with the ray casting (if you were close to a wall you could nudge yourself through the wall), as well as give a proper volume to the ship (if you check the previous video, you'll see the ship penetrates walls until the point at the center of the ship hits the wall).
I worked through the math for sweeping a sphere against a plane (which I'm confident I did correctly), however I ran into a fairly major problem that I didn't originally anticipate. I'm still able to penetrate walls. The collision detection code finds the point on the triangle plane that you're intersecting, and then tests that point to see if it actually lies within the triangle. This test fails at the edges of triangles, so the edge is able to penetrate the sphere. Thinking about this, it's not as simple as also detecting collision against the triangle edges, since the walls are two triangles, I think I'm really going to have to solve the penetration problem correctly like a real physics engine. Not something I'm interested in spending much more time on this month. Instead, I would simply plug in a physics engine (Box2D or more likely Bullet) and call it good.
Another option is to make the level environment simpler - I could make the levels tile based, and then I would do a proper 2D collision detection against straight boxes. I'm pretty confident doing a swept circle against a grid like this would leave me with robust collision. I'm not sold on a tile based level, and even if I do I might just plug in Box2D with it and try doing it myself later. I have to keep in mind the primary goal here is to get a *shippable* game by the end of the month, and plugging in an existing robust physics engine mitigates the risk of spending lots of time on my own collision routines. It is something I'd like to work out myself at some point, though.
I'm leaning towards plugging in Box2D. I'll think on it.
No pics/videos of the game for today - the game essentially looks the same as yesterday. Instead, here's a cat, because internet and physics.
No comments:
Post a Comment