Stack Exchange Network

Stack Exchange network consists of 174 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.

0
votes
1answer
47 views

How is raycasting implemented

I know what it's used for, I know what it does. What I am essentially asking is what is the math/code behind how it works? I'm aware that any custom implementation would likely be slower than an ...
0
votes
0answers
10 views

Python Pygame collision help with my game

im creating a game in pygame where a snowboarder will be going down a hill (2d). I need to figure out how i can detect collision when the snowboarder(shape of line) hits another line(hill) on one ...
0
votes
1answer
102 views

How to calculate the surface area of a mesh

I am looking for a way to calculate surface area of a 3D mesh object and found this code from a Unity forum: ...
0
votes
1answer
58 views

Perspective Matrix doesn't work OpenGL 4

I tried to implement my own perspective matrix and it doesn't work. I don't understand why. With just with my view matrix (without Perspective Matrix) I can see my mesh. Here my view matrix : ...
0
votes
1answer
75 views

Help me adjust this RPG logarithmic leveling formula! [duplicate]

I'm trying to find a formula that's fits the way I want my player to gain experience and level up. I know this is primarily opinion based but I hope someone can help me! I've used the following ...
0
votes
0answers
19 views

Create AABB Cube from click-and-drag user rectangle? AABB OBB Collision Detection

I'm trying to create a 3D cube from rectangle drawn by ther user's mouse (think click-and-drag selection). My end goal is to use this to implement entity click-and-drag box selection. If you've played ...
0
votes
1answer
23 views

Top down off-screen indicator, Unity3D C#

I'm working on a top-down 3D game where things spawn off camera. Movement only occurs on 2 axis (x and z). Rotation is about y axis. The player is in the center of the camera and needs to have ...
0
votes
0answers
35 views

2:1 Diametric Projection in 2D

I'm trying to implement a 2D isometric game, well diametric with a 2:1 pixel ratio. Trouble is the rotation matrix I made doesn't seem to work. It's off by a little bit and doesn't line up: I'm not ...
0
votes
0answers
21 views

How to detect if a point is below a bounding box (thread-safe)?

I am trying to cast a shadow on a set of points in Unity that are below a BoxCollider object (have an x and z that would be in the box but y is below it). I ...
1
vote
2answers
54 views

Trying to find a function to calculate attribute changes in a game

I'm coding a game where after every year depending on results the attributes of characters change. The game is a movie business simulator and here is a example of the ugly code I have in place now: <...
0
votes
1answer
41 views

Quaternion representing rotation from shoulder to hand

I am provided with 3 quaternions. One for the shoulder, one for the elbow, and one for the hand. What I want is to obtain a single quaternion representing the rotation from the shoulder to the hand, ...
2
votes
1answer
62 views

How can I express Logarithmic and Arithmetic spirals as segmented cubic bezier curves?

I am creating cubic bezier curves using this code from another question I asked. I would like to know how I can express Logarithmic and Arithmetic spirals as segmented cubic bezier curves.
3
votes
1answer
185 views

What is the physics behind a 2D gravity tunnel?

In Portal 2, there is a concept of an "excursion funnel", a beam of light that moves physical objects in a certain direction. Here is a link to a demonstration. I added a simple implementation that ...
0
votes
1answer
62 views

Combine rotation XZ (horizontal) with YZ (vertical). Math formula

I'm trying to make a rotation vertically and horizontally around a point at the same time but I'm not able to combine both. I have this formula for the horizontal rotation: ...
1
vote
0answers
40 views

Center of Mass for Convex shape in 3D

For an arbitrary convex shape in 3D, how can I calculate its center-of-gravity? I have face-normals, and the vertices for each face. @Ocelot No, it most certainly is not the average of the vertices, ...
1
vote
1answer
19 views

Project line segment onto a vertical line

If I had a vertical line (which its x is 0) and 2 vectors which connected together to form a line segment, would it be possible to "project" the line segment onto the vertical line? Eg. If all I had ...
2
votes
1answer
44 views

How to make a motorcycle running on a vertical circular track(loop-da-loop) without falling down due to gravity?

I am currently developing a game, motorcycle type game. Of course, my map is not just made up of simple line or curve. For example: a vertical circular track in the map. i've seen most 2D motorcycle ...
0
votes
0answers
46 views

Random Item Quality [duplicate]

I'm looking to implement something similar to what RimWorld does in terms of assigning a random item quality based on the skill level of the player. Here is their Wikipedia page for reference: https://...
0
votes
1answer
39 views

Help with the calculation of the usage of my speed stat

I am working on a freeroam, action RPG (before you read further, I am not noobish to programming, plus have friends to help with actual content rather than the base code). Anyway, I am trying in ...
0
votes
0answers
36 views

ray intersection of surfaces created by swiping a curve (shader)

What I want is to swipe any curve into a plane, axis aligned. I made 2d intersection of the cross section then the 2d hieght extruded: - first I want to compute ex: the xz intersections - then using ...
0
votes
1answer
24 views

Determine view-matrix with camera placed in a scene graph

My scene is organized with a simple scene graph where the child multiplies its transformation with the one of the parent. For normal objects, likes meshes, this works as expected, but I also want to ...
0
votes
0answers
15 views

Calculating the resulting velocity after a reflection

I am trying to do a simple reflection of a point entity off of an arbitrary surface that contains it. It doesn't have to be physically correct but essentially the goal is to do the following: ...
-1
votes
2answers
156 views

How do I calculate the total XP to reach a particular level, when each level takes 10% more?

How do I calculate the amount of XP for a level where the first level is 110, and each level after is 10% more than the last. Preferably to do without a loop because the levels will have to be ...
2
votes
1answer
49 views

Jumping to land x pixels ahead while not really moving (2D)

The player object in my game has its x-axis locked. It can only jump on Y. It's the ground that constantly moves to the left so that it appears like the player is moving to the right. The ground is ...
0
votes
0answers
14 views

Run 3ds Max animated train at specific speed in unity

I have a 3d Max exported Train animation which has animated at speed of 1 in 3Ds max Tool. Now, I have to run the animation at specific speed like 160 kilometer per hour (KMPH). I can easily set the ...
0
votes
0answers
30 views

Ray Sphere Interesection Distances WRONG

The discriminant is not working. This code produces incorrect distances from ray to sphere, but it can tell whether or not the ray does strike the sphere. HOW HARD IS THIS I'VE BEEN TRYING TO DO THIS ...
0
votes
1answer
61 views

libgdx - how to make enemies not overlap

I'm currently making a roguelike shooter in libgdx to get a better understanding of the library but I recently just stumped onto a problem where enemies would overlap each other while tracking the ...
0
votes
1answer
27 views

How can I add acceleration to the movement of an object in a game

Below is the code that I'm using to move an object: ...
0
votes
1answer
77 views

AABB test does not consistently detect edge-to-edge contact when bounds are very different in size

My function compares two AABBs for collision detection, and when they are around the same size it works fine, but I noticed that if I greatly decreased the size of one of them (or augmented the size ...
0
votes
1answer
70 views

Bullet Spray RNG

So I have a Nuclear-Throne like weapon system in my game, and I'm working on bullet spray. Originally, there was equal odds that the bullet sprayed at any angle within the spray range. That felt ...
0
votes
1answer
121 views

Isometric Architecture Map Game Data

I'm not sure this kind of question has been answered yet, if so i'm sorry to duplicate it. My question is rather simple : I'm creating a simple Isometric game with libgdx, i'm using Tiled but only ...
1
vote
0answers
47 views

Why are coordinates converted to [-1, 1] during mouse picking?

I am working on my first 3D game, which contains several vehicles placed on a board. I want to implement mouse picking of the vehicles. I found this great tutorial and used its code. But I don't ...
0
votes
1answer
41 views

How to implement level-player collisions resolution?

I want to create simple collision response system (physical simulation is not required now). It is needed just that player can't go through walls. I consider some variants: - Just create a set of ...
0
votes
2answers
38 views

Vector normalize in Unity

I was watching a tutorial about Vectors in Unity, I understood the meaning of normalizing a vector but I wanna know why do we normalize a vector and if we don't what will happen ?
0
votes
1answer
38 views

How to calculate angle for shooting bullet in 3D?

What I want to know is if I can calculate an angle similar to how I'm doing in 2D and update the x,y,z position of a bullet based on that angle in a similar manner I'm doing the update function below. ...
0
votes
1answer
37 views

Choosing the correct normal for a collision

I have taken the task of building a basic impulse physics engine. Circle vs Circle collision resolution has been done and I moved onto Line vs Circle. I can detect a collision and know that the normal ...
0
votes
1answer
63 views

Define a circle from a point on its circumference and an angle

I'm working on a 2D, top-down driving game with some basic AI vehicles. The AI Vehicles move along a bidirected graph of positions. Each vehicle has a current position (from the graph) and a target ...
1
vote
1answer
84 views

Convert Canvas Space point to local space of a rotated rect?

I got a quite tricky problem: I have my mouse position and my rectangle position in canvas space(screen space but with adjusted scaling). Now I want my mouse position converted to local space of the ...
2
votes
0answers
34 views

How do you find the collision between 3D boxes and 3D QUAD face meshes?

I have an axis aligned bounding boxes for 3D object collision, but I have a complex 3d mesh that's divided into 3d faces so I want to check for bounding boxes and collision with the faces of that ...
0
votes
1answer
154 views

From screen space to world space for a 2D game

I'm making a 2D game and I want the user to be able to position an object in the world using mouse input. After a while I found an answer to 'OpenGL Math - Projecting Screen space to World space ...
0
votes
1answer
86 views

Check whether a vector is to the left or right of another position

I don't know how to decide if my point is on the left or right side of another object. My first thought was to check if x-axis of object1 is bigger or smaller than object2's, but if my objects rotate ...
1
vote
1answer
63 views

Transforming a 2D Grid in 3D Space

Hi everyone, I'm trying to implement a 2D Grid in a simple 3D Editor. Here are some debug-rays I already implemented: Everything is working as intended as long as the object is not rotated. For ...
1
vote
3answers
52 views

Find Entity Orientation In Degrees Given Two Coordinates

I'm trying to find the orientation for an entity, as an angle in [0º-360º). I've searched for an answer and tried to implement something of my own, but it always fails on the edge cases. For a better ...
1
vote
0answers
70 views

How do I create the formula for calculate the damage of a skill

I'm trying to calculate the output damage of a skill. The skill can go up from level 1 to 100, it can scale with own levels and the attack of the character. Here some parameters Edit: I need a ...
2
votes
0answers
73 views

Handling a smooth movement over slopes in a worms like game

I currently have a worms like game with the worms style pixel perfect terrain destruction. Its working well for pushing things around and watching them fall, but for the players movement it feels like ...
0
votes
0answers
50 views

How do I find the texture origin using UV data?

I am writing a map decompiler for the video game Tron 2.0 and its map editor, DEdit. DEdit requires a set of three vectors in order to correctly map textures to each model. The vectors are what I ...
1
vote
1answer
71 views

how to put elements around circle with equal distance?

I know circle formula and know how to draw it. but I want put 4 points on it with equal distance from each other. how can I do that? I work with unity.
0
votes
0answers
20 views

How to find volume of convex 3D shape

I'm not sure what can be said that isn't in the title. The gist of it, is that I have a convex mesh delimited by polygons (can have more than 3 sides), and I want to find it's volume. Is there an ...
21
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?
0
votes
0answers
117 views

Computing depth from position of fragment in world space

I have a raymarching shader which computes the location of a hit on the scene in world space. float3 worldPos = ... ; I can verify that the world position is ...