Thursday 31 October 2013

I hate collision!!!!

Amongst all game engine coding, I hate collision the most! Every time I worked on collision, I'm always stressed by the math behind it. I'm, to begin with, is not really good with math. Because of it, I always try to understand it before implementing it. I googled around to understand the concept of ray tracing vs triangle. This site helped me understand it better. Then... start implementing!

I thought implementing after understand the concept won't be that hard but.... I stuck on a lot of stupid mistake which almost made me give up on it. To make thing worst, I'm always get motion sickness with the first person camera. Well, I'm glad Cody kept pushing me and supported me to finish it. I'm also glad he's always there to discuss with me. I found discussing a programming architecture before implementing it is super useful - especially when I need to implement something completely new. I am also glad I implemented my engine architecture nicely - over engineer in some people's eye. I am glad I spent extra time to make a nice game engine structure.

For this assignment, I didn't have to redo a lot of my collision engine structure. I just need to redo my CollisionEntity and upgrade my main collision detection from 2D OOBB to this 3D ray tracing. First this collision is done in 3D with meshes. It means I need somehow make the CollisionEntity know about the mesh: the triangles that made the mesh. Second this collision is done in 2 ways: forward and down. So, I need somehow make my collision entity know what entity I collided in forward direction and what entity I collided in down direction. Of course I also need the distance for both directions so that in the end of the loop I had the information of the closest forward-entity-collided and down-entity-collided. These information will be used to do the collision resolution. Thus, this is my CollisionEntity class:

CollisionEntity class

Then wrote the main collision detection part:

RayTracing function

I did my collision in both winding order. I am not sure how the artist make the collision meshes. Although I had already converted into DirectX winding order in my FBXLoader, I still decided to do both ways.

Is it done? No! Next is how to handle this collision, how to detect that this surface is closer than previous surface, how to know this object is closer than previous object? For the purpose of the 2 questions, I passed the collision distance and a bool of previous collision result in the RayTracing function. And in the end of frame, I reset these information. This works well for me although I still have some collision glitches.

No comments:

Post a Comment