# Questions tagged [mathematics]

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

1,848 questions
Filter by
Sorted by
Tagged with
98 views

### Rotating quaternion smoothly with acceleration and deceleration

I have this code for my linear acceleration and deceleration. ...
64 views

### How to do topdown collisions properly?

I'm trying to achieve grid/tile based collisions like "a link to the past"; here is an article showing it off (sliding off the corners and such). I'm currently using this type of collision ...
31 views

### Move vector A to vector B but stop X distance before reaching vector B and always be in front

I believe this is basic vector math, but I'm struggling with it. I have 2 objects (3D space, x, y, z), A (weapon) and B (camera). I want to move A to B's location, but then offset A from B so that it ...
79 views

### Problem with InverseTransformDirection and non-uniform scale

I made the plane to work with mesh vertices ...
83 views

### finding the angle of rotation of a 3d line

I have a line segment joining two 3D points AB, and a vector V which is normal to it. I need to know the angle of AB in the plane described with V as the plane normal, that is: in the plane of the two ...
45 views

### How to get all tiles along a straight vector path?

Let's say I have a 100x100 map of tiles where each tile is 16x16 pixels. How would I get all tiles along a path? For example, let's say I wanted to get a list of all tiles along the shortest direct ...
123 views

### Determining the price of a trade good depending on supply and demand of a marketplace

I've been meaning to add a market/trading system in my space-themed game where a player can buy from one station and sell it to another for profit, etc. (Examples would be Starsector, Elite: Dangerous,...
103 views

### Transactions on lists of coins of different values

For learning purposes, I am developing the first steps of an idle game with exponentially higher income numbers. Usual int, long, etc. can't store big enough numbers for that. I looked through many ...
41 views

### Angle between start and current rotation

I'm facing problem of the operations on rotations. I have a wheel with a start rotation of (0, 0, 0). The player has to rotate wheel 270 degrees in Y axis either left or right. During the rotation ...
72 views

### Offscreen waypoint indicator using X and Y screen position

I was wondering how I could achieve an offscreen indicator effect that helps direct the player to the next waypoint. My game is 3D, most solutions I have found are for 2D games (i.e Asteroids). See ...
92 views

### How to implement PCSS properly?

I'm trying to implement PCSS in OpenGL/GLSL, but I have problems understanding the details especially the conversions between the coordinate spaces. The existing implementations are so different from ...
38 views

### What is the math to project a 3D object's center onto a 2D plane?

What I really need is the x,y of the object when it is outside of the screen: I'm actually coding a UI in Objective-C, not a game. In this different kind of UI you navigate a 3D space with objects. ...
38 views

### How to interpolate colors around the spectrum of hues?

I wanted to generate a 7 segment display whose color brightness varies with time, this can be done by just using linear relationship. ...
641 views

### How does glm::lookAt produce a View Matrix?

Say we do this: glm::mat4 View = glm::lookAt(glm::vec3(4,3,-3), glm::vec3(0,0,0),glm::vec3(0,1,0)); And after printing to the console with glm tostring (column ...
22 views

### Efficient way to compare vectorial direction?

I have a bunch of random vectors representing a direction and four other vectors that we can distinguish with their pyramidal arrows at their extremity, they represent a boundary what i'd like to do ...
53 views

### Why my calculated value is far different from actual value?

I using CharacterController and not using a Rigidbody so I writing a script for downward velocity which is velocity=-9.81*(time) ...
76 views

### Is an inertia tensor in local-space always diagonal?

I'm looking at the implementation of a physics engine and I observe that the inertia tensor of a rigid body, in local-space coordinates, is stored as a 3 dimensional vector, rather than a 3x3 matrix, ...
56 views

### Slope detection in 2D platformers

I am currently shifting from unity to monogame to make 2d platformers. I am not aware of any sort of "raycasting" provided with monogame, I am aware of AABB collision detection and I am ...
172 views

### How to smoothly interpolate 2D camera with pan and zoom

I'm developing an animation application with a 2D virtual camera. The camera viewport can be positioned and scaled in the keyframes and is then interpolated to render the final animation from the ...
2k views

### How to create a spiral brightness gradient

I am stuck on creating a brightness gradient that looks as below(the values are continuous from the inner circle). What formulae can create such brightness gradient? So that when _Time is added to it, ...
97 views

### Is there a simpler way to simplify the if statement? [closed]

The code below generate angle and radius based brightness gradient. As you can see I need to use 3 if statement to define 3 circle, wonder is there a single code that can create nth circle ...
152 views

93 views

### Cylindrical billboarding around an arbitrary axis in geometry shader

I found an answer on this site relating to this question already, but it doesn't seem applicable in the context of my project. Basically I'd like to create a method which fits this signature: ...
164 views

### Create Mesh in gap between tiles (in Unity3D)

I am loading two kinds of tiles (meshes in tile format) in Unity, both are placed in the environment correctly but there is a gap between these two tiles (see the picture below). I want to fill this ...
37 views

### How to fill with empty space with retangles

I have a 'square' class with the representation of its limits from the variables x1, y1 and x2, y1 these variables define points 1 and 3 of the same, in this case the coordinates would be (0,0), (10, -...
46 views

### How to create a Decisecond(0.1second) function that can use in the code?

I create a circular object and pivot the minute and second pointer on the middle of the object as below. Below is the code I use. ...
59 views

### Object to reach height depending on its gravity and mass

A mathematician will probably think this was a silly question, but I'm not one and I'm in need of help :D I'm working in Godot and with its RigidBody2Ds (objects ...
291 views

### How to project a 3D circle/ellipse to 2D?

The 3D ellipse is represented by its center and the vectors for its major and minor axes and the 2D ellipse by its center, the length of the major and minor axes and the angle between the major axis ...
65 views

### What rotation needs to be applied to align mesh with expected axis of target?

I'm using LWJGL and JOML to create a 3D view of hexagons whose positions lie on a torus. I have a number (NxM) hexagons, whose centres and normals I have calculated to be placed on the torus to ...
86 views

### In a shader how to map UV coordinates of texture to the UV coordinates of a tile in a tile set?

I am writing a fragment shader for a tile set. In the shader I have the UV coordinates of the whole texture, however, I am interested in the UV coordinates of the current tile that is being rendered. ...
137 views

### How do you detect which side of a cube is facing up/down/left/right?

Please imagine a scene that shows a cube. Both the camera and the cube can be randomly positioned and rotated. How can you tell which side of the cube is facing up/down or left/right? Or in other ...
703 views

### World position into local position

I want to understand how I can convert world position of an object into local position. Especially how to deal with a rotation of objects. I'm testing transform.InverseTransform(...) methods. When ...
18 views

### Determining IF & WHERE a line intersects with a 2D plane (in 3D space) [duplicate]

The following problem I'm working on is for one of my favorite past-times: game development. Problem: We're in 3D space. I'm trying to determine if a line between two vectors in said space is passing ...
102 views

### Math question: How to move/extrude a cube's face in Unity?

The short question is: What's the math to move the face of a cube? I.e. how to stretch (or shrink) a cube in the direction of one of its faces? Here's a picture: The camera shows a cube (left). When ...
103 views

### c++/openGL 3D Bouncing Cube

I'm trying to write a little program with a bouncing cube but I can't find the right values for it. I have these lines: ...
25 views

### Statemachine to behaviour tree?

Background I was able to convert simple statemachines like this... Into a BT looking like this (Notation describtion)... ...
155 views

### How do I determine the player's grid position?

My original method for doing this involved taking the player's position, dividing it by the grid cell size, and rounding the result. This works for most cases except when I move my player up above y-...
337 views

### Verlet rope between two moving points connected with a spring joint?

I'm connecting two moving rigidbodies using a spring joint in Unity. Between them, a rope will be rendered using a line renderer and I want it to move realistically as the joints move, without physics....
59 views

### Frustum culling issue at oblique angles

I am using the following algorithm to test if my camera frustum contains an axis-aligned bounding box: ...
93 views

### Rotate relative to set point in a specified direction in a 3D space

I know there's a geometry formula to calculate the next point in rotation relative to another point in 2D but I'm working in 3D and I want to calculate the next position in specified direction as well....
1k views

### How to decompose a 4x4 TRS transformation matrix with negative scale?

As the title says I need to decompose 4x4 TRS transformation matrices and extract the proper scale vectors and the proper rotation vectors (or rotation quaternions). I know how to extract those ...
215 views

### Rotate object relative to camera position

I am trying to write code that is able to rotate object, based on camera position. So far I ended up with a code posted below. Moving mouse up and down (y input) caused to rotate object in y axis, ...
51 views

### How to tell which face of a cube is most visible to the camera?

Imagine a camera that shows a randomly rotated cube at an arbitrary position: The cube's pivot is in the center of the cube. This way its six faces could be referred as positive/negative X, Y or Z. ...
167 views

### How do I calculate/weight a diminishing damage formula based on N targets?

I'm making a game and had a look at the questions about calculating damage/diminishing returns here and here but I haven't quite been able to come up with a logarithmic function that satisfies this ...
87 views

### Calculating probabilities for a custom drop table system

I have a "drop table" / "loot table" / "item table" / "whatever you want to call it" system and I need to solve two Problems. Apologies in advance for the text ...
77 views

### How to Generate Level Map Based on Golden Ratio

I am trying to generate a map based on the Golden Ratio: a+b is to a as a is to b. I was looking at a JavaScript math library that had a built-in phi, but I wasn'...
39 views

### Can I get world-space z-near-plane vertices from projection matrix + z-near distance?

I'm trying to port ShaderToy VR shaders to WebXR (the new browser API for AR/VR devices). ShaderToy VR shaders expect two extra parameters: ray origin (view translation) and ray direction (unit vector ...
66 views

### Aircraft trajectory prediction

I have an aircraft that is controlled by player and i need to predict it's position at needed time. It's not a problem if the plane is just moving straight but most of the time aircraft is maneuring. ...