# Questions tagged [mathematics]

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

1,993 questions
Filter by
Sorted by
Tagged with
62 views

### Normalize an angle in unity

How can I normalize angle between min value and max value? like normalizing -1136316.78186234° between 0° , 360° or between 180° , 360°. Node: for now I'm using double value as angle. Thanks for ...
14 views

### Selection Box Not Positioning Correctly

I found some code that generates a selection box, but when I tried it the box was not starting where the mouse was and I couldn't find the issue. ...
30 views

### Matrix parent-child transformation for 2D positioning

I am working with matrix math for parent / child transformations. I have to modify existing calculations to keep child scale constant while also keeping child position relative to its parent. Here's ...
28 views

### Texture space Raytracing of cylinder primitive in godot shader for Helix interception

I have been trying to do raytracing of an helix in a spatial shader in godot 4.2, but apparently I missed something because the result is bloby and melty at the cylinder level. The basics is that I ...
• 327
54 views

### How to calculate velocity based on force at an angle

I have a 2D top-down jetboat that is moving (has a x, y velocity). I apply the velocity by multiplying against the delta time <...
1 vote
87 views

### Mirroring a Character's Position In a Shadow After Rotating 180 Degrees

Description: I am creating a 2.5D RPG. When my character moves from left to right, they rotate 180 degrees to face the new direction. Just like this example. They also have a blob shadow sprite that ...
• 190
3k views

### How hard to brake to perfectly smoothly reach the destination?

Goal I want the get the required minimum deceleration to perfectly smoothly reach a target. (The car's AI should know how hard it has to brake to be the perfect valet.) Research "How can I ...
• 213
70 views

### How to rotate spaceship quaternion to face target direction with constant angular speed?

I have an enemy spaceship, and I want to make it turn to face the player with (for now) a constant angular speed. The ship's orientation is a quaternion. How do I do this? Since this is totally free ...
• 111
1 vote
69 views

### How to calculate rotation needed to cancel out perspective shift

I have a direction vector that's pointing to (0,0,1) in local object space. How can I calculate rotation needed to rotate it on Y axis so that from camera's point of view it would look as if it's ...
• 13
110 views

### Max velocity for smooth deceleration to destination

I am able to update velocity of my agent every 0.5 seconds. My agents max speed is 5f/s and max acceleration/deceleration is 2f/s. I know how far away I am from the destination. How to determine ...
• 13
41 views

### Camera (View) in Euler angles

This is code (below) from original game project (90s years), I it study now. Used fixed point math. ...
• 205
63 views

### How to make calculating the inverse matrix more robust?

When I calculated the inverse matrix, I found that the error in using the float data type would cause the inverse matrix calculation error. Is there any good solution? ...
76 views

### Software rendering - compose View matrix

There is function compose View Matrix, it's software rendering project. Used fixed point math. phd_sin() and phd_cos() user defined functions implement sin() and cos(). Please explain this ...
• 205
93 views

### Normalized coordinates not translating to screen coordinates the way I need them to

I am making a simple game in C# using pictureboxes. I want to move a picturebox on a form. Once this picturebox is placed in a new location, I normalize its X,Y coordinates between [0, 1] and then ...
45 views

### Checking if I am looking through a window using angles

I am developing a mod for a game with a Lua api. I am trying to detect if I am looking through from behind a window when I shoot an enemy. For context, when I shoot through this window I apply a ...
43 views

### Determining a direction/projection/heading for an object in 3D space after it has been rotated

I hope this is a good place to find an answer. I'm not a math wiz and I've tried to tackle this problem many times over the past decade or so. I have a 3D space world, and I'm in a little space ship. ...
64 views

### Calculate damage when attacker has bonus but defender has resist

Let's say an archer does base damage of 50. But their equipment provides +30% bow damage to make the damage ...
• 101
1 vote
172 views

### Calculate path segments size

I have a problem more closely described on a picture below. The idea is that I have my agent in point A and I want to get to the point B. The problem is, that agents rotation towards point B is alpha ...
• 13
74 views

### How to correctly instantiate a cube over another, or side-by-side another one

In a Minecraft spawn system like, I can't make works correctly following code. Specifically, if I use Code 1 it works only when I instantiate a cube over another one, not one aside other. The ...
• 437
98 views

### How does vector raised to the power of another vector work?

I was watching this tutorial and at timestamp 3:03 he did this: This blows my mind because I didn't expect that to actually work, how the heck does that work ???? For example, if I have vector (2, 3, ...
• 117
97 views

### Angry Birds style aiming (ballistic trajectory)

Could you please provide guidance on how to create the curved part? regard,
109 views

### Min - Max Weapon Damage formula in video games

I currently working on an RPG game and I'm looking for are formula for creating/generating a min-max weapon damage for an item. Why in Diablo for example, when a weapon is dropped from an enemy, the ...
• 3
29 views

### Difference of angle by Y value

This code from game 90s years. For example on scene there is tiger as "item" and main character as "enemy". This code calculate vector or direction of attack tiger to main ...
• 205
107 views

### What this code do?

I investigate source code old game for 90s, dont understand math stuff. ...
• 205
103 views

### How to compute XP thresholds when scaling changes for each level range?

I am developing mobile game and I am stuck on an issue regarding proper player stats scaling based on level. As a parameters for the computation we have: base XP value multiple increment values (for ...
62 views

### Is this gimbal lock I'm hitting even with rotation matrices / quaternions?

I'm spawning a trigger box relative to another object using local offset. The engine I'm using does not provide a native function to make that conversion (at least in a way accessible to me), so I am ...
• 176
61 views

### When does normalization happen in the perspective projection matrix

I am currently watching this video where the instructor shows how the perspective project matrix is actually derived. There are a few things that I am still unclear of. Firstly he says we need to ...
230 views

### Simulate Velocity For A Projectile Moving Along A Spline

I'm using Unity's latest Splines package(v2.5) to move a projectile across a spline with speed. It works perfectly and the projectile moves across the spline to it's target with linear speed. But I'd ...
• 190
1 vote
110 views

### How to properly split damage against armor?

I am developing a third-person shooting style game and I want to implement an armor system. The system that I have envisioned does not reduce the damage to 0, but by half. So the incoming damage is ...
• 113
138 views

### Inconsistent Speed Of A Projectile Traveling On A Bezier Curve

What I'm doing: I'm moving a projectile to it's target along a Bézier curve with one control point. The projectile moves from Transform A to ...
• 190
146 views

### Calculating average ttk given accuracy and healing

I'm trying to calculate the expected ttk for weapons in my game but I'm having trouble because players can miss and enemies can heal. Let's say an enemy has 100 health and every second you have a $p$...
145 views

### How to tell whether an expression is independent from frame rate?

I'm working on a videogame where part of the logic involves increasing a value each render frame (a render frame is equivalent to a simulation step where the result is drawn on the screen). Frames can ...
56 views

### Determining meters per second in scaled terrain

I have a terrain with a width of 199 and height of 99 and I'm scaling this train by 500. What would be 1 meter in the new terrain, would it be 500? I'm trying to move my character in meters per second ...
• 1
195 views

### Test if a point is inside a 3D cuboid, given the 8 corner positions, through code

I'm trying to find to obtain if a point, let's call it "v" is inside a cuboid which every corner position named P1 to P8 I am trying to achieve this and in fact found some answers in some ...
• 121
126 views

### Euler Angle X is wrong after using Quaternion.LookRotation

I have an direction that I want the local player hub & camera to rotate at. The game handles this by using euler angles which Y represents the hub rotation on the horizontal axis & X ...
• 3
33 views

### Raycaster rotation problem

I am following lodevs tutorial on Raycasting https://lodev.org/cgtutor/raycasting.html. I was kinda successfull but for some reason while implementing a 2D Topdown view of the map and the player i ...
• 1
199 views

### A good genetic system?

I was trying to come up with a genetic system for my game. However, after doing the math I found the system I had in mind won't really work. Characters have 5 stats that can range from 0 to 12. What I ...
273 views

### How do I use these Unity math functions in Godot C#?

Here's a list of math functions I'm having trouble finding a direct function match for in Godot C#: ...
• 145
1 vote
79 views

### Adaptation of values from previous constant frame rate to new constant frame rate

I'm trying to learn how to adapt my old values to new values. First of all, I don't use delta time at all. My game has lock with 30 FPS and I want to lock it with 60 FPS, I wrote all my values in ...
• 11
1 vote
108 views

### Twin-stick backwards tank movement

I'm creating a 3D twin-stick tank game in Godot with C#. I have created the tank movement and rotation, separate of its turret, and it seems to be working properly. The issue: I want the body of the ...
227 views

### Calculation of far distance plane based on yaw and pitch for a map renderer

I'm working on a vector map renderer. I want to calculate the far plane for a protective transformation, based on the yaw, pitch, roll and height of the camera above the map. Yaw (looking to the left ...
• 123
1 vote
104 views

### Vertex Shader Sphere Projection and CPU Distance Calculation

I have multiple planes whose vertices are transformed to a position on a sphere in the vertex shader. The GLSL function called pointToSphere transforms a point <...
38 views

### Missing tiles when rendering an isometric Staggered tilemap in Unity

I'm trying to show tiles on an isometric staggered tilemap in Unity, but some tiles are missing. I think the problem might be with where I'm placing the tiles or some floating-point precision issues. ...
75 views

### How to calculate angular momentum of two colliding bodies about their shared center of mass in 2D?

I'm following this guide to implementing collisions in 2D physics. It shows this diagram, but I don't understand how to calculate the values of Da and ...
150 views

### Finding loss of angle and length due to rotation

I'm working on a targeting system for my 2d game. But I want to see the object in isometric perspective. My calculation is correct for 2d objects but it doesn't work for rotated in x axis objects. I ...
1 vote
283 views

### Why should a game include a range of possible damage values per hit?

I’m asking this because this reminds me of critical hits, preventing battles from being too predictable, BUT if I already have crits… why would I have damage ranges? Especially in action games, there’...
• 11
1 vote
1k views

### How to compare a vector to a rotation in Godot 4.1?

The Context In Godot 4.1, I have a third-person character controller. It's a CharacterBody3D with a child Node3D called PlayerContent. The visual components of the character (model, etc.) are all ...
• 163
29 views

### Isometric camera lookat

I'm trying to make my isometric camera follow my player or lookat any other object projection matrix is ...