Damn, that was a lot of work. On schedule today was sliding collision. This was on schedule because, ofcourse, it is weird if you can walk through walls and can’t slide past walls. I have always struggled with collision, though I’m not sure why. I have implemented a lot of collision detection systems in my prototypes in the past, but every single time I have had major problems with it. For some reason I didn’t have a bad feeling about the task at hand when I started coding this morning. I was almost looking forward to it. Nostalgia I guess. Naïve nostalgia.
I ended up coding for almost the whole day, working for a long time on a system that in the end is incredibly simple. I’ve tried about 5 different systems for (rectangular! -.-) sliding collision detection. And altough I got the collision detection working (with more work than expected), getting sliding collision working seemed like an impossible task. At some point I lost hope, because I had already tried 5 collision systems, all of them not working properly (altough the code looked perfectly fine. It’s depressing). I decided to take a break, go outside for a moment and buy some drinks for tonight. When I came back I had a striking epiphany. A true “EUREKA!” moment.
So I got back to work, and in mere minutes everything was working as intended. It turned out I was hopping back and forth between floating point numbers (numbers like 4.89) and integers (round, natural numbers like 2, 6 and 800) in an important function. That function in turn somehow messed everything up. All five of the systems couldn’t handle this little error. Which is ofcourse, expectable. Lesson learned.
I’m exrtremely happy but also extremely irritated at the moment. Collision detection gets to me every single time. I guess you could say collision detection… Is my kryptonite.