# Questions tagged [mathematics]

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

1,510 questions
1answer
89 views

### Smoothly moving an orbiting object back into orbit

I have an object that orbits the player's sprite with code that looks like this: ...
0answers
38 views

### Intercept an object with circular orbit

I basically have the same question : How can I Intercept object with a circular motion I tried implementing DMGregory's answer, but it looks like I always get the closest point from the ship in the ...
1answer
119 views

### What methods can be used to rotate a tiled structure?

I'm trying to rotate some structures that are locked on a grid-like structure. This means I'm looking for lossless ways to rotate the tiles. Maintaining proper distances are not important, I'm aware ...
2answers
385 views

### Convert gl_FragCoord range to fragment range

I'm working with shaders so far, but I'm not sure how I can make my shader gl_FragCoord relative to the window. To be more clear, this is what I have: and this is what I'm looking to achieve no ...
1answer
57 views

### Compare two x and y if they are in a valid range

Today my mind is a little foggy, the right thing was for me to do it the other day, but I will not, I will continue today. XD I need some help to think and find a way that works without bugs. What I'...
0answers
315 views

### Computing the UV coordinates of a 3D point that lies within a 3D triangle

From a triangular mesh I have a 3D triangle T represented by 3D vertexes v0, v1 and v2. Each vertex has an associated UV coordinate into a common texture image, represented as uv0, uv1, uv2. ...
1answer
47 views

### Work out the point on an ellipse given centre, radius, and direction vector?

I have a vector (white line), a centre and a radius along each of the semi-major and semi-minor axes of an ellipse (green line). I need to find the point where the white line intersects the green. I ...
1answer
173 views

### Ledge Detection with Plane Intersection?

i am working on a ledge climb system and I am currently refactoring it to make it more reliable. I am tracing with a sphere towards infront of my character. If it found something, I trace downwards. ...
1answer
78 views

### Calculating correct normal direction from multi-variable function

I am working with a plane model which I am offsetting the vertices on the up axis to look like waves by using the function: Sin(vertex.x * frequency) * amplitude + Cos(vertex.y * frequency) * ...
2answers
38 views

### In track and field dash, determine starting speed from a final time with acceleration

I am developing an athletics game, and working on the mechanics of the 100 meter dash. The player controls an athlete, that during the race has acceleration and a max speed. To win the race, the ...
2answers
281 views

### How do I balance these numbers in a rock-paper-scissors attack system?

I have three arrays of numbers. If you take a random one from x, it will 'win' more times than a random number from z, which will win more times than a number from y, which will win more times than a ...
1answer
117 views

### How do I project the Earth globe on a flat plane with minimal distortion?

I want to build a game where the game map is the planet Earth. The game map needs to be on a 2d plane, with the Earth texture projected on it If the player walks endelessly in one direction, it should ...
1answer
59 views

### Why don't Sin and Cos give expected results when rotating off axis around a non uniform shape?

When I rotate a rectangle and draw straight lines along it's edge using Sin and Cos the lines don't follow the edge as the angle approaches 45 degrees, why? The exact same code works just fine when I ...
2answers
209 views

### Determining the first future intersection possible between ships and a planet

Somewhat of an extension of this. The Problem I have a ship being launched from a planet, and I would like it to travel at a constant speed and direction such that it intersects another planet the ...
2answers
302 views

### How to make a sprite blink with Libgdx?

I want to make a sprite blinking like this: ...
3answers
227 views

### How to create a boomerang-a-like path?

For the GitHub Game Off Jam, I plan to create a small game with a boomerang. But I don't know how to build the equation that will update the boomerang position. I try to build a direction vector and ...
0answers
315 views

### Unity - Quaternion.AngleAxis for two axes

I am creating a character controller where the camera follows the rotation of the player, and allows the user to click and drag to rotate the camera around the player, and lerps back when its released....
0answers
148 views

### Setting relative anchor point via matrix

The page at https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html provides an example for rotating around the center of the image: ...
1answer
45 views

### Delta time causing comparison issues due to floating points

I am working on a game in Game Maker Studio: 2 and am using Delta Time for the time. I understand what it is, how to get it, and how to use it, but I am running into issues when I need to make ...
1answer
248 views

### 2d Scale width and height based on distance

I'm drawing a health bar on top of each player. I transform 3d position to 2d. I would like to draw it smaller when distance increases. Any simple math for that? Let's say bar width is 30 and height ...
2answers
80 views

### Approaches on detecting if a car should steer left or right considering a next direction

I'm developing the A.I. of my racing game, and I'm having an unforeseen problem. I manage to get the bot to drive by itself by accelerating in the direction of an angle that is returned using the ...
1answer
405 views

### Rotate an object to face a point with glm::lookAt

I want to rotate an object to face a point, such as the monster look at the player. For that I've decided to use the glm::lookAt function. However the following does not yield good results: ...
1answer
17 views

### Moving object with preset timelapse

I am a newbie game developer. I have one problem. Consider the following case. I have a simple game with only one object - a ball. A ball can move only up and down from one side to another. A User ...
2answers
80 views

### How to calculate all points in a 2D grid defined by an arc, given a starting point and range

I've an unit in a 2d (integer) grid-based game, which has a bearing. Now I want to display an arc, with a given radius (for instance simulating a 90 degree cone of a sensor with respect to the bearing ...
0answers
94 views

### Point System For Answering Categorized Questions

We are currently developing a gamified e-learning website. The website will have a point system where the users can gain points by doing either asking or posting questions. Questions are grouped by ...
1answer
61 views

### Evenly distribution of 2 or more shapes given their x and y points inside a bounding box

I have a set of dynamically shaped objects, How do I distribute them evenly either Horizontally or Vertically.The objects are surrounded by a bounding box and the objects are placed at x,y as shown. ...
1answer
130 views

### Draw/“rasterize” irregular circle onto a 2D grid

I'm using the midpoint circle algorithm to choose cells on a 2D grid which outline a circle. However, I need to incorporate some random noise so that I get an irregular circle, and this method won't ...
1answer
114 views

### Subdivided Icosahedron Hex/Pent grid efficient rendering?

How to performantly display a hex/pent grid on a subdivided icosahedron? I have a subdivided icosahedron planet used as the "board" for a strategy game. It usually has anywhere between a few thousand ...
1answer
95 views

### Camera math: How to calculate the horizontal and vertical angle from the look at vector

I'm using the PerspectiveCamera class in C#/WPF to implement an FPS style camera. For that, I would need to offset the camera's horizontal and vertical angles every time the mouse is moved. The ...
1answer
104 views

### How to rotate a rectangle body around a fixed point?

How to rotate a body around a point? The body has x, y, speed and angle. Coordinates of the body relative to its center. Additional conditions: point position and distance from body to point.
1answer
227 views

### How to wrap a components position using angles (i.e horizontal compass)

I'm trying to make a horizontal compass. The compass is made up of UI components: panel (with mask), with a child UI Image (the compass image). Here is the compass from Fallout: As you turn around, ...
2answers
1k views

### Projectile Aim Prediction with Acceleration

I'm trying to solve the classic shoot moving object problem but with acceleration attached to that changes it from a quadratic to quartic formula but my math skills are not this good sadly as i prefer ...
1answer
45 views

### How to fire a projectile in a certain direction with constant velocity (directX 9)

I am working on a top down 2d shooter. I am trying to make the bullets go at a constant speed (in pixels) in the direction of the mouse. I am having trouble doing this. My bullets fire directly 45 ...
2answers
184 views

### How to make a layered health bar in GML

I am currently working on a game in Game Maker Studio 2 where the player character is capable of increasing their maximum health beyond a starting value of 30, by increments of 10. I want to represent ...
1answer
83 views

### How do I make three attack systems so that there is a rock-paper-scissors distribution, but equal average?

In the game, there are three attack systems: Strength-based, Magic-based, and Psionic-based. The damage each type deals will be multiplied by their own modifier. The one for strength I have come up ...
1answer
301 views

### Calculating the latitude & longitude of a raycast hit point on a sphere

I am working on a game where you look at a sphere and get the latitude and longitude of the position. I get the position on the globe with a raycast along the direction the user is looking. Using ...
3answers
2k views

### Why use Time.deltaTime in Lerping functions?

To my understanding, a Lerp function interpolates between two values (a and b) using a third value (...
1answer
511 views

### Is it legal to use formulas from a professional game?

The Pokémon series uses a total of 5 different formulas to determine how much experience is required to get to the next level. Likewise, in RPG games, each character has a formula for determining when ...
2answers
4k views

### How to design a damage formula in an RPG which keeps weapons with different attack speeds balanced?

I'm making a mobile rpg game, an infinite one where there is a loot system like Diablo 3. Weapons have attack and speed, armor pieces have a resistance value (not percentage). The formula I'm using ...
0answers
690 views

### How to model Engine RPM in a racing game ?

I'm currently developing racing game in unity. My car gets torque via a torque curve that I implemented , a simplified version of a curve.But to get the torque from the curve I need to input the ...
1answer
32 views

### Calculating coordinates of a point

I struggle to find coordinates of point B in the picture below. I know the positions of A and C, the length of arm ...
0answers
70 views

### How to rotate ship while moving forward

Somehow I'm feeling there's a way to improve this mess but can't figure it out. It's the code between "//-----------------". ...
1answer
287 views

### Matrix multiplication order for multiple model transformations

I have a problem in terms of what frame of reference, I should construct, scaling (S), rotation (R) and translation (T) for a model matrix (in that order). Let us assume the use of glm (or glsl), i.e. ...
1answer
45 views

### Get next tile by given angle

I am new to game development, and I have been building some game with LibGDX engine. The following function might make you feel bad The function I am going to show, is accepting the current rotation ...
1answer
49 views

### Fixed distance increments between two Vector3 positions

I have two Vector3 positions: Vector3 start = new Vector3(1f, 1f, 1f); Vector3 target = new Vector3(5f, 5f, 5f); How do I transform gameobjects a fixed amount ...
1answer
159 views

### Why does my Character Jump only Half as High?

I am trying to implement simple Newtonian physics for my game. However, my character only jumps half of the height I would expect him to. Physics says that the take-off velocity (impulse) ...
2answers
228 views

### Prevent tile layout gaps

I'm making a map viewer where you can specify where tiles go in a map and then see it on the screen, translate it, and zoom in and out. Here's a picture showing the tiles used to make my example map ...
1answer
131 views

### Calculating real time moment of inertia around arbitrary axis in 3d

I have a 3d rigid body consisting of multiple triangles forming a closed mesh. I know how to calculate the moment of inertia around an arbitrary axis by splitting up the mesh into simpler shapes and ...
0answers
349 views

### SceneKit-Convert a rotation vector into rotation matrix

I'm very new and I'm studying this ARKit code from RPasecky/CubesInSpace on github where he/she convert the point of view 's rotation vector into a rotation matrix ...
0answers
32 views

### Object orbiting around center in 3D [duplicate]

I am having a trouble with creating an object that will orbit around another object in 3D. I understand that in 2D you use equation: ...