# 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
832 views

### Rotate an object with 'Quaternion.Slerp' in world space

I'm currently working on a multiplayer skydiving Unity game in which i rotate the players like this: ...
161 views

### Why Are These 3D Square's Pixels Spaced?

So i'm currently attempting to write a 3D renderer. From no prior knowledge because I want to challenge myself. But I'm stuck here, and thought I'd bring it to StackExchange because I always see ...
40 views

### Get 2D mouse delta along 2D angle?

I'm trying to develop my own transformation gizmo (with x, y & z handles/arrows the user can grab and move, like in game engines), however, I'm not sure how I should calculate the 2D mouse delta ...
515 views

### Rotate object such that a child object is facing a target (3D)

Given a parent object A and a child object B, how do I find the rotation of A such that B is pointing toward the position of a target C. This is a simplified way of solving 'what angle does the torso ...
177 views

### How to get a translation vector in a certain direction? SAT

I'm using the seperating axis thereom for discrete collision detection. I have code to find the minnimum translation vector (or distance) to seperate two shapes but how can I adjust it to get a vector ...
68 views

### how to debug calculating tangent space

[][]2 there's problem calculating tangent space and look.... it seems there is no problem with UV code and my shader is 100% no problem. I just copy and pasted tutorial code which works well.. I ...
98 views

### 3d complex collision and trigger detection [closed]

I'm a Unity developer and I use monobehavior functions to dot things like collision detection. I have read about articles about collision detection. Most of them work with geometrical structures like ...
255 views

### Score balancing and progression limitation based on stars

Introduction I'm creating a game where the player can obtain 1 to 3 stars for each level based on the score it gets (based on the completion time). The levels are grouped in "worlds" each of which is ...
75 views

### Intersection point of two lines with given formula

I have following formula to check the intersection of two line segments: ...
39 views

### Physics - Determine how much thrust to apply at each thruster for linear/angular acceleration [duplicate]

I have a question somewhat similar to this one: 2D Spaceship Thruster Movement - Turning. I have a ship with thrusters placed randomly on it (not necessarily symmetrically), and I need to know which ...
112 views

### Mathematics: matrix-to-quaternion conversion in left-hand coordinate system

I am implementing a typical skeletal animation system, and it requires the usage of quaternion to interpolate rotations between each poses. The asset I import only has a transform matrix for each ...
66 views

### How is math connected to video games? [closed]

I have to do a project for my math class in which I choose a topic and connect concepts we learned to it. I chose video games, and I was hoping someone could help me. Possible concepts: Quadratics, ...
81 views

### Bullets moving with the camera, not the world, Java 2D

I'm building a simple 2D Top-Down shooter game in Java. I simply cannot get this to work: I'm moving camera and world differently, world is moving when needed (when not in one edge, so it gives nice ...
2k views

### Getting Vector at 90 Degrees from provided vector

I need a function that can take a vector as an input and provide a vector that is at a 90-degree angle to the provided vector. I understand that in 3D there is an infinite amount of vectors that could ...
26 views

### Algorithm for clipping convex quadrilaterals

I'm dealing with hardware that uses quads as its polygonal primitive. Not triangles. A triangle can be expressed by setting 2 of the 4 equal to each other for a degenerate quad. For the 3D engine, I'...
26 views

### Interpolating bent textrues

I am currently making a pressure heat map that will be overlaid on a bent shape (let's say cylinder). I am using a 2d texture that is mapped to the object. The pressure points are also mapped to the ...
30 views

### Correctly map a Mount&Blade style aiming rectangle to the projectiles flying direction?

So I implemented a game mechanic where drawing a bow will display a shrinking rectangle that should represent the shooting accuracy. The rectangle is smallest after about 1.5 seconds of drawing the ...
51 views

### Simplistic level system (Math reliant question)

So I've been checking some games to get ideas for my own. Some designs I've reviewed rely on a few variables like: Current level Current exp Exp to next level I aim for a simplistic design where ...
751 views

### Shadow casting in 2D OpenGL

I´ve read several articles, tutorials about shadow casting and I think that I understand the way how it works. However I miss some of the steps. Here is included my order list: Fill framebuffer with ...
276 views

### How to program an experience-based levelup system where experience carries over to the next level?

I'm new into programming, and i've tried to do a system of level up. Here it is : ...
166 views

### Can a set of 3D positions be separated by plane?

I have 3 points in 3D space: A, B and C. I also have another set of 3D points: P, Q, R, S, T and U. What would be the simplest algorithm to figure out if there exists a plane that completely separates ...
283 views

### Why doesn't games use CORDIC for sin and cos?

If the game devs add CORDIC sin cos calculation to their games, their games will have much better FPS. Why do they use normal sin cos function (e.g. Math.sin) instead of CORDIC?
100 views

### How to line up rigidbody velocity with speed of moving floor

So, I have a player who remains in the same X position. the floor moves from right to left underneath the player, and I am using tiles of 1 unit. Here's my jumping stuff: ...
1k views

### Raycast not hitting a collider

I have the following simple raycast from a capsule on a cube: ...
74 views

### Get relative heading/angle from global coordinate system

Suppose the player is facing 0 degrees in Global/World space. And the Local coordinate system is that of a unit circle. How do I obtain the Local angle if given the Global angle? How do I obtain the ...
143 views

### Find third point in right triangle [duplicate]

I need to get position marked as green X. I have the helicopter's world position and the player's world position. I want X to always have an angle of 90 degrees. Player heading is ignored. How can I ...
280 views

### Separating axes theorem problem

I´ve been following this tutorial : http://www.dyn4j.org/2010/01/sat/ to help me understand and implement the SAT for collision detection in my games as I want to add a support for polygons. However, ...
1k views

### Relative quaternion rotation (delta rotation) produces unstable results

Use case: I have a currentRotation quaternion and a targetRotation quaternion and need to calculate the relative rotation ...
69 views

### Set velocity at position?

In Unity3D there's a way to add force at a position and a way to get the velocity at a position. I'd like to be able to set the velocity of a rigidbody2d at a local position. My current solution ...
1k views

### Getting the angle between three points?

I have three points, A, B and C (stored as Vector2 in Unity). I am trying to find the angle at point B if there were a line AB and and a line BC. I know, this should be a simple google search, and I ...
47 views

### Third Person SpaceShip Camera Directx9 follows objekt but gets weird after moving object

We have the following code. It should follow the game Object in every step but it does not. In the beginning we can rotate the object where ever we want and it works but after moving it some the ...
549 views

### Convert skew to rotation + scale

I'm working on a plugin for Unity that takes data extracted from a 2D animation software and convert them to work with Unity Animator. I'm blocked with the "skew" property. Here are the data I got in ...
2k views

### How To Rotate A Vector around A Pivot Point

In Unity, I'm trying to figure out how to rotate an object around a pivot point. I found a snippet of code over on the regular stack overflow, but it wasn't working even close to correctly. I have ...
2k views

### How can I get the normal vector for a plane from a set of vertices?

I'm working on a HLSL / C++ little project to going over my graphics work, and I am unsure how I am to get a facing vector from a vertex polygon. I can't seem to find the formula. The positions are ...
59 views

### What is the mathematical explanation behind this implementation of simulating eyeballs roll in eyes?

I want to simulate eyeballs roll in eyes and I have found and forked this implementation in codepen.io. This is exactly what I need. ...
275 views

### How to implement stress/strain mechanics in voxel terrain?

I am in the process of developing a Minecraft-like world where the terrain is divided into voxels. However, I would also like for unstable configurations of landscapes to collapse predictably. For ...
74 views

### Get an exponential number between two numbers

Bit of a math question here... lets say I want to supply a number (any number) and I want the result to be clamped between 0 and 1. For instance, see the following graph. Is there a way that when ...
116 views

### Detecting single circle within multiple circles area

There are multiple circles with same radius, given another circle in different radius, how to detect the another circle is fully in multiple circles area. Image below shows left samples is in the ...
363 views

### Average for damage formula (Min-Max Attack - Min-Max Defense)

We wanted to create a quick spreadsheet to rapidly adjust enemies' Attack and Defense from players' estimated values of Attack and Defense. One of the key values to adjust is the "hits until dead", ...
117 views

### How do I maintain the world pitch, roll or yaw of child objects?

I've got an application where I'm trying to display an object in 3D, with information provided by real-world accelerometers and inclinometers - sensors that pick up the angle of the equipment, ...
193 views

### How are these physics formulas translated to this code?

So how exactly does something like $v_f = v_i +a*t$ translate to something like self.vel += self.acc in code? or $d=v_i*t+\frac{a*t^2}{2}$ translating to ...
592 views

### Applying Rotation Vector to OpenGL camera or “view matrix”

I'm building an augmented reality application where I want objects on the screen to move with respect to the orientation of the phone. For example, if the phone is held still - the object stays at the ...
53 views

### Are there any math limitations on the near plane in a perspective matrix?

I've noted that if in the perspective camera I put near plane to a low number like 0.000001 and far plane to 1000 my render has ...
41 views

### How do I go about rotating a point that is not on the origin? [duplicate]

I need to know how to rotate a vector that is not on the origin. I believe I have to multiply the vector that is not on the origin by the rotation matrix, then multiply by the first matrix negated to ...
1k views

### how to convert FoV into zoom 2x, 3x, 4x…?

so I have the value of the FoV in degrees, now I need to convert it to a zoom value of 2x, or 3x, for scopes and binoculars. I placed some objects equally distanced between each other, but when I ...
42 views

### Physical attributes as a function of age

My workerclass has physical attributes such as physical_fitness and sexual_fitness which are ...
162 views

### How can I control a game 2d car mechanic from acceleration & speed to just 1 value?

So I have a car in a 2d game that runs on acceleration and speed, two values that have a max. The acceleration is small, under the value of 1 and it rises by an incrementation. The speed is large ...
2k views

### Get Angle with respect to 360 degree

I have fixed object, around its an object is moving in circular shape. Now i am willing to get my moving object angle with respect to fixed boject like form 0 to 360. How can i do this. i tried this ...