Random Equations

I spent some time this week doing some more work on the random encounters, trying to get it to behave the way I want. The way I wanted it to behave is that there are many social factions in the game, and each planet has an affiliation with a particular faction. The closer you are to a planet of a given faction, the more likely you are to run into one of their ships. I wanted it to fall off pretty sharply so that you would be fairly likely to run into ships from the faction when you were close to the planet, but then extremely unlikely when it started getting farther away. I also wanted the likelihood of meeting a ship from a faction to be higher if there were several planets from that faction close together.

So I determined upon a solution where after the map is created, each planet updates all of the nodes in the map with a ‘presence’ value, based on how far away the node is. Once all of the factions have contributed their presence to a node, I use the total faction presence to calculate the likelihood of encountering a ship there, and the approximate strength of the force that you are likely to encounter. I dug up some equations that would give a nice slope, decreasing the presence, but never quite hitting zero presence. The presence curve looked like this:PresenceGraph0It’s got a rapid fall off, with a long tail, pretty much what I wanted, but when I added some code to visualize how likely you were to run into a particular faction, I got the following output:FactionPresence0The green circles around planets mean that the planet belongs to a particular faction, and the green half circles show how likely you are to encounter a ship from that faction at the given node. Notice how it doesn’t matter how far away from the planet the different nodes are, the probability is basically unchanging. I did a lot of tweaking of the numbers being fed into the equation, but nothing really seemed to help. No matter what, the probability was basically the same across the board.

I figured that it was because none of the nodes were close enough to the planets to take advantage of the high values at the start of the curve, they were all basically stuck in the long tail where there wasn’t a lot of variation. Fortunately, I finally stumbled upon a solution, I squared the input distance, and used that rather than just a straight distance. With a little tweaking that rendered a presence curve that looked like this:PresenceGraph1As you can see the graph goes for a ways before it starts dropping off again. This also gave me the following result from the game:FactionPresence1You’ll notice that there is a large disparity between the areas close the the planets and the areas far away from the planet.

I’m continually amazed, and pleased, at the wide array of skills demanded by game development. Before now, I’ve never had to search through equations and try to grasp the way that numbers interact with each other in order to come up with a way of modeling a desired behavior. The opportunity to learn and apply new skills is just one of the awesome perks of working on a game in my spare time. You should try it, you’ll love it, I promise.

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Random Equations

Comments are closed.