How do YOU solve unfamiliar math problems?

I ask because I found myself with the task of finding the interception point for a projectile fired from my ship. I was looking at a book on Game AI which provided a decent solution but it was for a guided missile like projectile, or an AI chasing a player (either one). I needed to find a way to find the interception point using the target, the shooter, and his bullet velocity. Thinking it might be fun to try and solve it myself, I set out to do just that.

Several hours later I kind of gave up. I was just very confused. If you give me a math problem from class, I could probably solve it because I know what is related to. However when I get to a problem of my own desire I’m a little lost on how to solve it. Is it a calculus or algebra problem? What method should I use? How do I make sense of it all?

That isn’t to say that I couldn’t solve it. In high school I managed to drive a dot around a screen in a VB .net game I made, complete with its own render loop and slope ratio’s for changing the direction of travel. I hadn’t even passed Pre-Algebra at that point.

That came with a lot of frustration and dedication to the problem. I realized that if I mapped out the slopes for all common directions, I could then use them to change how my dot moved. Then I ran in to a problem regarding scale of each step using an arbitrary slope (these were not unit circle slopes, as I had no idea what that was). How I solved that problem escapes me right now but I know I did eventually do something multiplication or division to do so.

I guess today’s students don’t like to actually learn how to solve these things. I’ve heard that before. I mean if you can just Google a solution then what is the incentive to solve it yourself if you care more about the solution than solving for it?

So my question is how do you solve a non-textbook math problem?

If I can’t wing it, I usually Google it. Or sometimes use Google for inspiration on how to wing it. Once you get a basic idea of math used in Game Dev, it gets a lot easier to put different solutions together to fix something.

Sometimes you can even find a totally different approach to your problem.

4 Likes

To add to that, I think one of the more important things to remember in Game Dev is that smoke and mirrors are okay. It doesn’t matter how you make something work, as long as it looks the way it should on the player’s end.

10 Likes

I’d like to preface this post by saying I’m a professional (I get paid) developer in the GIS industry.

I am horrible at math. I used to struggle with it as a kid, and I think I got myself so worked up and repeated “I’m horrible at math” enough in my head that it became true. It got worse when I moved schools in the 4th grade, and the school I moved to was further along than the one I moved from, so I felt even more behind. For this reason, at the age of 32 I still don’t have a clue how to do long division.

I was really good at taking tests, though, and scored well on a placement test that made the school recommend me for all the advanced placement classes going into 6th grade. This was fine for English and such, where I was advanced, but I was way over my head with any of the Math courses. Regardless, a combination of being a good test taker, faking my way through homework assignments, and some good old fashioned cheating meant I made it through my required courses by the skin of my teeth all the way through high school.

So my current way of approaching complex Maths when writing code? I avoid it at all costs!

@SebastianLague has a fantastic series of YouTube videos on Unity/game development, and while going through the world generation series, he does some fun math stuff to generate falloff maps for creating islands. While the math is loosely explained, I needed to create other falloff map types, and didn’t have a clue how to approach this mathematically.

Instead, I modified the FalloffMapGenerator class to use two AnimationCurves, and build the falloff map using those values. Now I can reap the benefit of complicated functions by drawing instead of having to know the Math behind them! Granted, my current solution doesn’t offer me all the flexibility I’d like, and I need to invest a lot more time figuring out how it all works and how I can get my system to do everything I need, but I’m proud of my creative avoidance solution to a problem I’ve been dodging all my life!

So I guess this classifies me as a “Wing It” guy.

Pull them apart and solve piece by piece.

If direct solution is not possible, apply bruteforce and rough guess the solution.

Guided missile projectile is matter of solving two line equations, pretty much. (origin + direction * t = origin2+direction2*t). You can simplify it by flattening problem to a plane - dir1 cross dir2 will create normal ,which creates a plane in which you coculd try to solve the problem.

In case you’re dealing with, say, trying to hit a plane with mortar shell (which flies in arc), you can start with rough guess of parameters (heading of mortar), ran it through simulation formula, see how far you missed simulated target, adjust parameter in direction which should reduce the error, and try again. Repeating this process ten times will result in fairly high preccision. IIIRC similar process is used in inverse kinematics.

I use a combo of what @Jacob_Unity , @Schneider21 and @neginfinity said.

I try to avoid it because complexity is never good. I break the problem down into simple steps and do some experiments continually adjusting based on results. If still “no go” I google to get an idea how others have solved similar problems and using the fundamentals (not their actual math heavy solution) I then create my own simplistic solution. Again usually requiring a series of experiments continually closing the gap to the desired outcome.

2 Likes

I googled for an HSL/RGB conversion algorithm recently because I knew I wouldn’t even want to try it myself. It’s mostly the difference between “how can I do x” (being rather open ended) and “what is the equation for x” (with a pretty hard and set solution).

I google stuff and try said stuff until it works or makes enough sense to do it myself.

…Was there some other way?

I guess what I was getting at was I’d like to be able to develop solutions myself. That is important because in some software development areas there are no solutions you can google. I don’t think there’s many problems in game dev that haven’t been solved, that is true.IMHO iits always good to be able to solve these things yourself because the day may come when you find a problem you need to solve that you can’t google.

I study CS and Calculus is a required class. I feel at least a bit better knowing that I can at least do differential calculus now (I passed it this time round, lol), it seems many game devs don’t know much advanced math.

I guess this skill is important kind of like eating your vegetables are when you’re little. It will serve you in the future if you do it now… but in game dev I don’t think we may ever need to use Calculus (much).

Also I try to avoid frustration and confusion, though I’m no stranger to either of them. Knowing how to solve these problems can help one avoid such things (mitigate them at least).

Isn’t this approach the brute force approach?

Anyway since my math suck too, I either use some code I found googling or solve it with simple math and brute force. Sometime not knowing math it play to my advantage cause simple math also mean simple calculation and I come out with computationally inexpensive solution.

It is not a brute force, because you start with a guess and then adjust parameters in the direction that will reduce the error. Brute force is trying all possible options.

I believe this is related to Newton’s method, and is one of the standard appraoches to inverse kinematics.

I thought it was still a brute, smarter brute, but brute since you are using a step by step approach.
Then it’s the same approach used in cloth solvers too.
In my AI I am switching between several solution methods, starting with the fastest and less reliable and switching to to slower and more brute method if I can’t find a solution before X iteration and finally switching to finer steps, if even this can’t reach the solution yet.

Also when dealing with players, always tell them that RNG and probability are involved… that way they cannot reverse-engineer your game and tell you that you screwed up the math.

For the problem mentioned, that is a pretty standard physics / linear algebra problem and should probably be found in Google pretty easily.

1 Like

I don’t understand the question. It’s been about a decade since I encountered a math problem that was unfamiliar. :stuck_out_tongue:

The trick is learning how to solve math problems. Combine that with some basic algebra and you are good to go.

Here is the process I follow.

  • Define what my problem is. What information do I want to gain? What information do I want to have? What characteristics does the solution have? This normally includes drawing a picture of the problem.
  • Google to see if anyone else has solved the same problem. Laziness is a virtue. I have no desire to repeat the work of others.
  • Develop the equations that relate the inputs to the outputs.
  • Perform a degrees of freedom analysis. Is my problem even solvable?
  • Solve the problem
  • Verify the solution meets the criteria in step one
2 Likes

Its those two steps that elude me, specifically, lol

This.
Often times real math/physics isn’t very interesting (in a gameplay sense). As long as it is internally consistent and looks cool, faking it can be cheaper and easier to manage.

1 Like

Developing equations is a big topic. Fortunately there are equations for most scenarios out there. Google is your friend here. One of the greatest mathematicians of all time was an advocate of ‘standing on the shoulders of giants’.

If there are no equations out there, here are a few tips.

  • Get to know the subject matter intensely
  • Run some empirical exporements to gather data
  • Try fitting a few common equations to the data via eyeball (excel is great for this, it will even do the least square regression and give you the equations)
  • Consider just faking it with a polynomial or an animation curve

Solving the problem is normally just straight forward algebra. No secrets there. Aside from knowing how algebra works. A high school math text will cover you off here.

This. It’s not just realistic physics isn’t as fun. We’ve also been conditioned not to expect reality from games. Throw a realistic character controller into an FPS and players will complain it doesn’t feel right.

In some ways I agree (in the sense that whatever is more fun is most definitely the right choise) but I don’t necessarily agree that real maths and physics isn’t interesting when used in the average game. I think it’s a basic human instinct to be interested by the mysterious ‘truth’ in things, it’s part of our pattern-seeking nature. Whether it’s a question of how a ball moves as it glides through the air, or a word with a double meaning, or whatever, in general I think we’re attracted toward things where we sense that there’s a fundamental principle there that will show us something about reality.

The way I see it is that realism is often good, but usually only in terms of aesthetics and not in terms of how the player must behave. For example, in a tomb raider-style game it looks great to have fluid and realistic body movement physics and it enhances the game, but the speed of the movement shouldn’t be realistic, although I think that’s more of a question of correlating time-wise a huge body movement with the twiddle of a thumb.

I guess the point is to preserve the beauty of the way that physics animates reality when building a game, but without the restrictions that it imposes, and very definitely we should not include our shortcomings whether it’s technology (‘realistic’ star citizen would be boring) or physical abilities (not being able to jump 20 feet is boring!).

1 Like

Hence my choice of the word often. However most games are based in unreal worlds/universes. Sci-fi, fantasy or cartoon / stylized. “Real” physics are expensive, short cuts both for cost and dramatic interest are employed. Virtually all vehicle physics in games are highly stylized for dramatic purpose (with a few rare exceptions). Certainly for the handful of realistic games, you want the appearance of sort of reality, but even COD type games, there is much more stylistic physics than real physics.

2 Likes