Trending
Opinion: How will Project 2025 impact game developers?
The Heritage Foundation's manifesto for the possible next administration could do great harm to many, including large portions of the game development community.
Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs or learn how to Submit Your Own Blog Post
When Keeping It Simple, Stupid is a coding mantra that can and should be applied to all parts of game development. And when you can't keep it simple, sometimes an outsider can help.
KISS (Keep It Simple, Stupid) is a design philosophy that is often repeated as a mantra by software programmers. The foundation of the belief is that you should keep your code distilled down into its most basic pieces, and avoid over-engineering your solutions. Your problems have probably spawned from a very simple situation, and your solution should be equally as simple. I recently found out just how much this principal applies to all aspects of game Development, including design. And even if you lack the ability to keep it as simple as you need, bringing in others can help!
A few days ago, I was working on a top-down tactics game, and I got stuck. I was trying to do line-of-sight calculations, and find valid targets for ranged attacks. My guns weren’t allowed to shoot around corners(as is a limitation for most guns ), so I had to stop my target-search whenever I hit a wall. This is pretty standard stuff in the world of gamedev. But I started to get all muddled up when I was dealing with partially hidden targets. This was a tactics game, after all. I had to make a decision of what percentage of the target square had to be in sight before I allowed a hit.
Thinking myself clever, I remember the way that my Dungeons and Dragons group handles line of sight. Looking at any of the four corners of your starting tile, if two full corners of the target tile are visible and unobstructed, you have line of sight. This is pretty simple in the real world, because we can usually lay a ruler down or physically trace a line from one square to another. It is just 16 lines to compare in my script, right? Super easy.
So, I can easily calculate the line going from point A to point B. But now, the really important thing for me is figuring out if those lines intersect with wall tiles. Time to get a list of wall tiles, and do collision detection on each one. Loop through the tiles, find out if each of the 16 lines impacts any of them. In fact, we can abstract that down a bit more to define the wall tiles as regions on a graph, and check if our previously calculated line intersects.
So now, I break down a starting tile location and a target tile location, calculate the 16 lines for its corner checking, and then quickly pull the graph regions of each wall tile, and then run a nice little equation to figure out if my lines ever intersect the segments. Great. Time to get started coding! Its been a while since I’ve used any of those equations, but it’ll be “nice” to pull out my linear algebra book for the first time since college and give it a go. Maybe I’ll get started on that… tomorrow.
At that point, I stopped working on my game for the evening, and I also didn’t return to it for 3 more days. Every time I thought about my game, I couldn’t get up the motivation to go through with all of that math hassle. This seemed like way too much high level logic to handle a single line of sight calculation. This was going to be hundreds of computations for each possible target that I wanted to check line of sight against. Not only would it be difficult to implement, it would be slow to run.
WOAH WOAH WOAH Eric, time to keep it simple, stupid.
After a few days of procrastination, I was discussing my predicament with some of my friends. After my long winded explanation of line intersections, they asked me “Don’t you already have a way to find a straight path to a location for movement? Just check all the tiles you would move through, and see if they block line of sight.” I was dumbfounded. This problem had taken me three days, mainly because I didn’t want to deal with the huge complexity of my “clever” way.
I had line of sight working later that night. It ran quickly, too. Each line of sight check only checked 3-5 tiles usually, based on the size of the rooms and the path taken, and that alone was enough to run faster than the 16 line segment checks I had initially thought about. The fact of the matter was, I was looking at the problem too closely and for too long by myself. Once I had to break it down for someone else, the solution seemed obvious.
Keep it simple. If your problem is about checking a straight line path on a grid, don’t try to fancy it up. Find the straight line, and check your grid. If you can’t keep it simple, go talk to someone who doesn’t know about your project. They’ll keep it simple. They have to, because they don’t know better. Complexity can kill motivation, and kill productivity. Keep it productive, keep it simple.
Keep it stupid.
You May Also Like