Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [mathematics]

Mathematics questions deal with the arithmetic, geometry, calculus, formulae and other calculations used in the development of a game.

163
votes
16answers
129k views

What math should all game programmers know? [closed]

Simple enough question: What math should all game programmers have a firm grasp of in order to be successful? I'm not specifically talking about rendering math or anything in the niche areas of game ...
117
votes
12answers
104k views

How to develop RPG Damage Formulas?

I'm developing a classical 2d RPG (in a similar vein to final fantasy) and I was wondering if anyone had some advice on how to do damage formulas/links to resources/examples? I'll explain my current ...
50
votes
2answers
6k views

What is a quaternion?

What is a quaternion, and do how they work? Also, what advantages do you gain using three points on a 2D plane? Finally, when is it considered good practice to use quaternions?
47
votes
7answers
11k views

Moving ships between two planets along a bezier, missing some equations for acceleration

OK, I already posted this over at math.stackechange.com but didn't get any answers :( First of here's a picture of my problem, the description follows afterwards: So I got all the points and ...
47
votes
3answers
2k views

How to determine which thrusters to turn on to rotate the ship?

The configuration of the ship changes dynamically, so I have to determine which thruster to turn on when I want to rotate the ship clockwise or counter clockwise. The thrusters are always axis aligned ...
46
votes
7answers
51k views

What are atan and atan2 used for in games?

I am having some trouble understanding Math.tan() and Math.atan() and Math.atan2(). I have ...
46
votes
4answers
7k views

A ball hits the corner, where will it deflect?

I need to brush up my trigonometry and hope you can help here with a simple mathematical model. Here is my model so far in the image attached. I am aware that the frame animation has other problems ...
44
votes
2answers
18k views

How to create adjustable formula for RPG level up requirements?

I'm trying to create a formula that can be modified simply by changing two values: number_of_levels, and last_level_experience. This is to enable people modding the game to change the levelling ...
39
votes
4answers
6k views

Why are radians preferred over degrees in game development?

I've been looking up the definition of radians and found out that mathematicians prefer them because they are derived from pi instead of being completely arbitrary like degrees. However, I have not ...
38
votes
2answers
9k views

Why do we use the Pythagorean theorem in game physics?

I've recently learned that we use Pythagorean theorem a lot in our physics calculations and I'm afraid I don't really get the point. Here's an example from a book to make sure an object doesn't ...
33
votes
5answers
8k views

How can I calculate current level from total XP, when each level requires proportionally more XP?

In my game, XP needed to reach the next level is Current Level × Level Threshold. Given that, how can I get my current level from the total XP ever earned? For example: ...
29
votes
6answers
6k views

Are there any disadvantages of using Distance Squared checks rather than Distance?

I use distance squared checks for basically all my distance (vector3 length) checking, due to the performance increase from not incurring a square root (like in plain length checks). From the looks ...
28
votes
4answers
9k views

How can I move an object in an “infinity” or “figure 8” trajectory?

When I want to move object around point I do: point.x *= cosf(timer.timeElapsed); point.y *= sinf(timer.timeElapsed); How to make point move on eight or ...
28
votes
6answers
20k views

How do idle games handle such large numbers?

Just wondering how games such as Tap titans and Cookie Clicker handle such large numbers. I am trying to implement an idle game however the largest number format supported by C# is decimal. I am ...
28
votes
10answers
59k views

In Pong, how do you calculate the ball's direction when it bounces off the paddle?

I'm trying to wrap my head around this very Hello World-y problem in game development. I've created a TicTacToe game in XNA so I guess the next step would be a Breakout clone. Keep in mind that I ...
27
votes
12answers
17k views

Random number in a range, biased toward the low end of the range [duplicate]

I have an input of two values, let's say 1 and 10. Lesser numbers should overall occur more often in the output than higher numbers, while there is a peak in the probability at #2: ...
27
votes
7answers
4k views

Continuous weighted random distribution, biased toward one end

I am currently contributing to a particle system for our game and developing some emitter shapes. My uniform random distribution along a line or along a rectangular area works fine - no problem. But ...
27
votes
8answers
5k views

How can I prevent small numerical advantages from dominating the balance of an encounter?

I've been tinkering for some time with a game and I'm having a fair amount of trouble with something: I have two characters, each of whom have attributes (about ten) in a range (between 1 and 20). I ...
27
votes
11answers
33k views

Comparing angles and working out the difference

I want to compare angles and get an idea of the distance between them. For this application, I'm working in degrees, but it would also work for radians and grads. The problem with angles is that they ...
26
votes
6answers
19k views

How can I come up with a simple diminishing return equation?

There are formulas out there for a diminishing return equation; however, those usually involve exponential. What other ways are there for coming up with such an equation? Take, for example, the ...
25
votes
3answers
6k views

What does the graphics card do with the fourth element of a vector as the final position?

From this question it appears you would want a four-element position vector, as it is simpler to modify its position with matrix multiplication. On its own this would imply the fourth element should ...
24
votes
3answers
52k views

Moving an object in a circular path

I want to move one object (dot) in a circular path. How should I change the X and Y coordinates to accomplish this?
24
votes
3answers
10k views

Is there a faster sine function?

I am working on generation 3d perlin noise. The C# Math library seems like overkill for what I need since most of its functions use double percision. I use Math.Sin() in several places to generate the ...
24
votes
5answers
9k views

How to quickly calculate the sight area in a 2D tiled game?

I have a matrix of tiles, on some of that tiles there are objects. I want to calculate which tiles are visible to player, and which are not, and I need to do it quite efficiently (so it would compute ...
24
votes
3answers
6k views

How do I lerp between values that loop (such as hue or rotation)?

View Demo I'm trying to make the joint rotate smoothly around the center of the canvas, toward the angle of mouse pointer. What I have works, but I want it to animate the shortest distance possible ...
23
votes
6answers
5k views

How to optimize the distance function?

While developing a reasonably simple RTS-like game, I noticed my distance calculations were causing an impact in performance. At all times, there are distance checks to know if a unit is in range to ...
23
votes
6answers
15k views

How can you visualize a quaternion?

When I visualise a three dimensional rotation matrix, or scaling matrix I visualize it as three axes. Is there a similar way that I can visualize a rotation quaternion?
23
votes
7answers
3k views

How can I Intercept object with a circular motion

I am creating a 2d space game and need to make the spaceship intercept a planet. I have working code for straight line intercepts but cannot figure out how to calculate the planets location in a ...
22
votes
3answers
4k views

Are there 3D projections other than orthographic and perspective? [closed]

The question is pretty much in the title. Are there notable 3D projections other than orthographic and perspective that could be used in a 3D system such as OpenGL? In particular, are there any that ...
22
votes
4answers
1k views

What kind of gaming experiences does hiding game play stats and formulas cultivate?

There are varying degrees of providing players with information on their characters abilities - including but not limited to showing players their character's stats and how they tie into formulas such ...
22
votes
1answer
2k views

Why do transformation matrices always have an extra dimension? [duplicate]

In 3D math I always see matrices with one additional dimension. For example, in 3D graphics, matrices are always 4x4 and in 2d they are 3x3 matrices. Can anyone explain why?
22
votes
5answers
1k views

Beyond “Novice” Game Projects

I was reading this answer on the type of math a game developer should know and this part really stood out at me: ...
22
votes
4answers
8k views

Bezier curve arc length

See also: same question on Math.SE How can I find the arclength of a Bezier curve? For example, a linear Bezier curve has the length: ...
21
votes
3answers
1k views

What's so different/complicated/useful about vectors?

Forgive me if this isn't considered a real question, but it is something I am genuinely confused about. I constantly hear other game developers talk about how using vectors are very useful, but also ...
21
votes
6answers
9k views

What is a good linear algebra book for game programmers? [closed]

I was told that I should start learning Linear Algebra in order to create good games with good physics. I'm reading Linear Algebra book and it's completely foreign to me. The author starts out with ...
21
votes
6answers
6k views

What are some methods to represent train tracks?

I looked into this a while back for a small project, but didn't get too far. I'd like to create a small program that lets a user draw a train track and then allows a "train" to follow said track on a ...
21
votes
1answer
8k views

How to convert mouse coordinates to isometric indexes?

I draw isometric map with tile 64x32: ...
20
votes
4answers
3k views

Calculating the output of two armies fighting

I am programming a strategic game using Flash. The game works very similar to the famous game "Travian". My problem is as follows: I am trying to make the calculation of the troops lost as a result ...
20
votes
5answers
16k views

Do I need the 'w' component in my Vector class?

Assume you're writing matrix code that handles rotation, translation etc for 3d space. Now the transformation matrices have to be 4x4 to fit the translation component in. However, you don't actually ...
20
votes
4answers
20k views

Calculating minimum velocity of the projectile needed to hit target in parabolic arc

If I have a point which I want to hit at the end or during a parabolic arc, how would I calculate the needed x and y velocity?
20
votes
1answer
2k views

How can I evenly fan out a hand of cards?

Given a set of playing cards (rectangle images with a width and height) how can I rotate and position each one so that they appear in a 'fan' pattern, much like you would hold a hand of cards in real ...
19
votes
9answers
16k views

How do I sort isometric sprites into the correct order?

In a normal top-down 2D game one could use the screen y axis to sort the images. In this example the trees are properly sorted but the isometric walls are not: Wall 2 is one pixel below wall 1 ...
18
votes
6answers
28k views

Best C++ Math Library for Game Engine? [closed]

I'm looking for a fast opensource C++ math-library for my game engine with the following features: fast (sse?) vectors matrices quaternions suitable for both opengl and directx
18
votes
2answers
10k views

How can I generate a navigation mesh for a tile grid?

I haven't actually started programming for this one yet, but I wanted to see how I would go about doing this anyway. Say I have a grid of tiles, all of the same size, some traversable and some not. ...
18
votes
3answers
765 views

How can I maintain a rectangular formation when units are added or removed?

I've got bots in a rectangular formation with rows and columns. A problem arises when a bot is added or removed from the formation. When this happens, the bots have to rearrange themselves so that the ...
18
votes
1answer
7k views

Determine arc-length of a Catmull-Rom spline to move at a constant speed

I have a path that is defined by a concatenation of Catmull-Rom splines. I use the static method Vector2.CatmullRom in XNA that allows for interpolation between points with a value going from 0 to 1. ...
18
votes
7answers
2k views

Do I need a Point and a Vector object? Or just using a Vector object to represent a Point is ok?

Structuring the components of an engine that I am developing along with a friend (learning purposes), I came to this doubt. Initially we had a Point constructor, like the following: ...
17
votes
2answers
21k views

How can I project a 3D point onto a 3D line?

Let's say I have a line defined by two points, A and B, both in the form (x, y, z). These ...
16
votes
6answers
31k views

How to convert a number from one min\max set to another min\max set? [closed]

I'm doing terrain generation and I have a perlin library that is giving me random numbers between -1 and +1. I want to convert this to the scale of 0-255. What is the proper way to do this?
16
votes
3answers
813 views

Building a Plattformer - How to determine if a player is allowed to jump?

I'm building a simple Plattformer Jump n' Run Style game. I do not use tiles - instead i've geometrical shapes for my level entities (and the player is one too). I finished my collision detection code ...