Mathematics questions deal with the arithmetic, geometry, calculus, formulae and other calculations used in the development of a game.
0
votes
1answer
35 views
libgdx - Math for wall collision when adding velocity
I've created a game which spawns a random colored ball in the top or bottom of the screen and moves to random direction with this method.
private Vector2 position;
private Vector2 velocity;
private ...
0
votes
0answers
36 views
Dot product not working as expected
Recently I am learning dot product,
While below code works from Unity's documentation,
http://docs.unity3d.com/ScriptReference/Vector3.Dot.html
public Transform other;
void Update() {
...
1
vote
1answer
56 views
Rotating A model in 3D so it matches its direction of movement
So I have a model of a spear and when it gets thrown I want to set the orientation of the spear to its direction. ( I also want to use this for other things like bullets pointing in the direction ...
0
votes
0answers
32 views
How to spin a 2D quad in place using only matrices?
In short, I have a textured 2D quad (a sprite). I would like to rotate/spin it about the z-axis (coming out of the screen) using nothing but matrices.
If I do the following to a transform with scale ...
1
vote
0answers
16 views
A question about Decal projection
From my understanding, there are several different ways to implement decals, from screen space, to copying geometry, but I can never find an explination of it's math.
So what exactly is the math ...
2
votes
3answers
113 views
Accelerated movement in a specific time to a specific point
I am trying to move my sprite in a specific time to a specific position while using frame-independent or time-dependent movement. My sprite is also accelerated every frame to simulate gravity. I know ...
8
votes
2answers
840 views
Get water flow direction vector from water normal vector
Im stuck developing an important detail of my game water: Making it flow downwards!
Considering a typical 3D world in wich water tends to go towards gravity g=(0,-1,0) , and having the normal of the ...
1
vote
2answers
88 views
Calculate values in a game, which depends from stats and balance them
So, I am basically lost at this point, trying to balance things.
In design phase; I did assign certain values to stats (imagine a standard set of any RPG you ever playe, to make things streamlined).
...
0
votes
1answer
40 views
Convert Mouse Coords into Isometric Tile ID
Using GameMaker Language, I'm basing off their Adavnced Examples. How can i convert the current mouse position into a tile position?
The mouse coordinates are 0,0 from top-left
This is the function ...
0
votes
1answer
29 views
How does this point2LineDist() method works?
I was browsing Wolf3D JS port and bump into that method :
/**
* @description calculates distance between a point (x, y) and a line.
* @memberOf Wolf.Math
* @param {number} x X coord of point
* ...
0
votes
1answer
30 views
Which three points to use to calculate a frustum plane?
So I have a view frustum I'm going to be using for frustum culling. I have a method that finds the cross-product of three points but since each side of the frustum has four corners I don't know which ...
0
votes
2answers
65 views
Why does Mathf.Log(x) return infinity in this case?
I'm facing an unexpected behavior due to computational limits, I guess.
I have a function Log(x) which, for some high value in the Fibonacci series n 187 = 5.38·10^38 returns Infinity.
Is there a ...
0
votes
1answer
48 views
Frustum culling only working at certain angles
So how I'm doing this is a little sketchy but I plan on changing it to either AABBs or spheres once I get it working. So the problem I'm having right now is that the frustum culling I've implemented ...
1
vote
1answer
66 views
How to clamp a direction vector within a direction pyramid?
In 2D you can specific an angle range such as [-45 to +45] and clamp a 2D direction vector within that angle range. I want to have something similar for 3D. I want to specify the allowed directional ...
0
votes
3answers
146 views
How to calculate the closing speed of two objects
I have the 2D positions and 2D velocity vectors of two objects. How do I calculate the closing velocity ? I want to get the closing speed.
Think of one jet tracks another jet with radar and you want ...
0
votes
0answers
42 views
How to get correct quaternion value from real world to screen?
I'm writing an application (not a game per se, but close enough) where we use attitude sensors (an IMU) in the real world to affect the orientation of an object in the application's 3D space (OpenGL). ...
0
votes
2answers
32 views
Object has its heading stored as Euler angles. After it makes a turn, how do I calculate the new angles?
Assume said object is an aircraft. I store three angles (in degrees) that describe where it's headed: yaw, pitch and roll - in that order. Let's say the plane is flying vertically, upwards. The angles ...
3
votes
3answers
135 views
Increasing chance of good loot after multiple tries
I'm looking for a way to make chances of getting better loot increase the more you've looted. I do not want it to be possible to get a rare item the first 5 times and not being able to get an epic ...
0
votes
2answers
43 views
Detecting position within a circle
I need to detect the position of a knob on a touchpad. I need to detect if it is in particular areas and if so, which one. The sections, of course, being the colored parts.
I know that the black ...
1
vote
2answers
84 views
Calculate Position on Tile Map by single Index
I stumble about a Math Problem for calculating a Position on a dynamic tile-map.
So i got a List of Tile Entities. Every Tile got his one unique Index Value and i have to set the parameters for Map ...
0
votes
3answers
45 views
Velocity Relative To A Vector
So I have a velocity vector b in world space and I have a "pointing" vector a in world space. I need to know how to make the velocity vector to be relative to the "pointing" vector. Better explanation ...
1
vote
1answer
41 views
How to smooth hand drawn lines?
So I am using Kinect with Unity.
With the Kinect, we detect a hand gesture and when it is active we draw a line on the screen that follows where ever the hand is going. Every update the location is ...
0
votes
1answer
39 views
Getting vector relative to other vector in rotating object
So I have a rotating object a. It is rotating at non-constant speed around it's local x axis. It is parented to object b. When the object a rotates, it's local x axis stays facing the same direction ...
2
votes
2answers
61 views
Calculate matrix transformation components separately
It is possible to calculate the translation, rotation and scale that were used to build a matrix?
I mean if I have a matrix M can I calculate the rotation, scale, and translation it represents?
Of ...
0
votes
1answer
45 views
Normal to an edge of a polygon, from a point inside the polygon
Suppose that I have a closed boundary that is represented by n points. Using these n points I construct a polygon with n sides. I have a point P(x,y) that lays inside the polygon.
I want to draw the ...
0
votes
1answer
56 views
How to calculate acceleration and deceleration
I have a car with speed x, and can accelerate at a rate of 0.5 m/s^2, and can decelerate at a rate of -0.1 m/s^2. Maximum speed is 20 m/s.
To accelerate the car speed, at each frame I need to do:
...
1
vote
1answer
55 views
How to calculate distance of travel needed get achieve speed x?
I have a boat traveling at 20 meters/second approaching destination x. Destination x has a range radius of 10 meters. What I would like to do is make sure by the time the boat arrives within 10 meters ...
3
votes
0answers
68 views
Filling Closed Shapes
Game Engine : Unity 5.1
Developing on Windows 7
Hello,
I am using Vectrosity to draw some some shapes on screen run time. I also need to fill these shapes and none of them are really trivial shapes. ...
11
votes
3answers
4k views
Attack vs Defence and who is the winner? [closed]
I am in the process of creating a new simple game in mobile and I've spent several days on the following part.
For simplicity, let's say that I have two fighters. The only attribute of them is ...
0
votes
0answers
29 views
How to find visible planes in a world of boxes
I have a world where each object is a box:
Each box has position x, y=0, z, dimensions width, height, depth. The boxes are never rotated. Each box is composed of 5 planes (left, right, front, back ...
1
vote
1answer
77 views
2D sunrise in Unity
I see a lot of guides on how to create sunrise in 3D space, but I can't find much information on how to do it in 2D. In 3D, you rotate a lightsource around itself, but in 2D, I need to move the object ...
-1
votes
1answer
67 views
C++: from LWJGL to C++ with OpenGL
I've been trying my best on porting my 3D game from Java to C++, but to no avail.
I use only LWJGL with OpenGL but I cannot find any other library in C++ that supports as much as LWJGL does for Java. ...
21
votes
12answers
3k views
Random number in a range, biased toward the low end of the range [duplicate]
I have an input of two values, let's say 1 and 10.
Lesser numbers should occur more often in the output than higher numbers.
1: extremely common | most likely
2: very common |
3: pretty ...
0
votes
1answer
99 views
Day/Night - Rotation from a sine wave
I recently found this question on stack exchange with a great answer that showed how to condense game time into a sine wave, where 1 = midday and -1 = midnight
Converting time of day into a smooth ...
3
votes
1answer
60 views
Determine if set of connected tiles can fit inside grid
Feel free to edit the title; I had a hard time figuring out how to explain it in a single line.
Here goes. I'm trying to generate these grids automatically, and randomly.
I have a grid of 25 tiles ...
1
vote
1answer
55 views
Mesh slicing/knifing with multiple planes
I have a ginormous mesh which I want to cut with multiple planes.
For simplicity I want to know how to cut a mesh with single plane and repeat the logic.
Consider a X-Y plane of coords (1,1,0,0) = ...
0
votes
1answer
86 views
Convert transform from world to local space
I have a hierarchical node system. Given a world space transform, I need to obtain the transform for a specific node in local space.
My Node class has the following method.
public void ...
8
votes
2answers
160 views
Terracing mountain features
I'm looking to replicate a procedural terrain effect I found on a portfolio/blog site a few days ago.
Quoting the site, the terracing was generated through, "multiplying [the final height] by some ...
1
vote
1answer
78 views
Implementing time step in main game loop
So ive read both http://gameprogrammingpatterns.com/game-loop.html and http://gafferongames.com/game-physics/fix-your-timestep/ and I kind of understand how I'm supposed to do it, but some parts are ...
-4
votes
3answers
54 views
Get bullet movement direction?
I have two objects, A and B, at two different points. I want B to fire at A. B's shot moves so far x and y every frame. How do I get the angle it needs to travel at as two numbers, one representing ...
1
vote
0answers
65 views
Euler angles to directional vector
I wanted to implement a directional light system in my game, and instead of passing the direction to the light, I chose to use an angle, and only later convert it to a directional vector, so it is a ...
3
votes
2answers
121 views
Vector math to calculate the rotation and drift of a tectonic plate?
I've been following the excellent Experilous procedural planet generation post, trying to recreate it in Java using libGDX. My planet is simpler, as it lacks any distortion of the mesh. It's just ...
3
votes
2answers
97 views
understanding spatial hash function behaviour and Knuth for int64
I implemented open-indexing sparse 2D spatial HashMap, and I'm quite satisified with performance ( ~30-70 CPU cycles to get object at particular location for size ~16 Milion objects ).
However, I ...
1
vote
1answer
48 views
What is the best way to check for intersection of two bounding boxes, given a minimum and maximum Vector3 for each one
I have a BoundingBox object which holds two Vector3's (x, y, z), one for the minimum point and one for the maximum point. (-1.5 0 9 | 1.5 3 10)
What is the best way to check for any intersection or ...
0
votes
1answer
32 views
How to enforce touching within a ring shape?
I'd like to have the player moving the finger within the shaded ring:
The game should be able to detect "out-of-boundary" events once the finger moves outside the ring. How can I accomplish this?
2
votes
1answer
115 views
How to avoid Gimbal Lock on Rubik's Cube [duplicate]
I am making a Rubik's cube program. That will simulate a Rubik's cube. I am having problems with gimbal lock. I need to know how to avoid it. To my understanding I can either multiply the x, y, z ...
23
votes
5answers
5k views
How do idle games handle such large numbers?
Just wondering how games such as Tap titans and Cookie Clicker handle such large numbers.
I am trying to implement an idle game however the largest number format supported by C# is decimal.
I am ...
3
votes
1answer
66 views
Frustum Culling: How to calculate if an angle is between another two angles
I am trying to implement frustum culling but got stuck on how to determine if the angle that the object is from the player is in the FOV of the player. So basically I have the following information:
...
1
vote
0answers
36 views
How to find or compute or look for overall/max RPM by simply checking for rotation?
I find it hard to determine the wheel RPM since I'm only making a simple 2D game of rotating object via Z-axis. I wanna try this solution but I got no change since I'm trying to find the RPM from a ...
13
votes
1answer
1k views
Is * calling *= (or *= calling *) slower than writing seperate functions (for math library)? [closed]
I have some vector classes where the arithmetic functions looks like this:
template<typename T, typename U>
auto operator*(const Vector3<T>& lhs, const Vector3<U>& rhs)
{
...