A lot of my research involves games. Video games to be exact. And so a lot of my current research and frustration has involved game programming. I’ve done very little game programming before this ended up being my research topic. And most of my ‘experience’ has involved game programming that more closely resembles board games or card games. Much easier to implement and the rules are easy to understand and follow.
Video game programming turns out to be a lot more difficult then expected. It doesn’t help not having a proper background in it. It doesn’t help that I’ve been pretty much teaching myself the tools from scratch. And almost everyone I’ve met who works with this game engine gives me a wince in sympathy. I’ve come across innumerable bizarre problems and quirks of the system.
But yesterday’s problem/solution just takes the cake. Because it shouldn’t be a solution. And yet it is. I have a simple scenario. I want two characters to kick a ball back and forth. It should follow something like this:
- P1 kicks ball towards P2.
- P2 pauses briefly before moving to ball.
- P2 stops at ball and positions ball in front facing P1.
- P2 kicks ball towards P1.
- P1 pauses briefly, before moving to ball.
- P1 stops at ball and positions ball in front facing P2.
- Repeat from 1.
Not so complicated. However, I coded two different versions where p1, once kicking the ball, would pass ‘control’ over to p2 and vice versa. And in both of them, characters started behaving oddly. They’d flicker. And bounce around the screen both vertically and horizontally. This behaviour would end up being extended to all the characters in the scene. And the ball would start jumping around the scene before flying off the edge of the ‘world.’ So just odd. And frustrating. And nothing made sense, because there was nothing in the code that should cause any of this behaviour. But it was becoming so bad, and so quickly (less than a minute after game start), that I was ready to can these characters from my ‘game.’
Until today. For some reason, I decided to try writing a script that just moved the ball back and forth between the characters, but actually ignored the characters. Just a ball moving somewhat randomly. I did this to see if I could determine if the error was on P1 and P2 or on the ball. Well, the ball moved fine. So I expanded the code. And it turns out, having the code on the ball decide who should move and when fixed everything. Although what it fixed exactly, I have no idea. Because I still don’t have any idea what was causing the problems in the first place.
I do know that I’m so frustrated with this programming experience, that I have a lot more admiration for game programmers who work in 3D environments. Kudos to them that there isn’t a lot more odd behaviour in games. And I’m going to being think a lot more if this is an area I actually want to end up in.