Skip to main content
10 votes
Accepted

Guided Missile with Constant Time

The edit is reassuring. :) Okay, here's a straightforward update loop... Assuming when we fire the missile we initialize remainingFlightTime = 5f then... ...
DMGregory's user avatar
  • 135k
9 votes
Accepted

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

Because on the x87 (the x86's FPU) the fsin, fcos and fsincos instructions are much faster than software CORDIC. On other architectures such as PowerPC and ARM you usually can rely on an optimized ...
Stephane Hockenhull's user avatar
6 votes

Why are rotations in 2D game engines often counter-clockwise = positive systems?

Why have we arrived at the convention that rotations should be counter-clockwise then, even in engines where positive y is down? Have we? Let us try CSS: ...
Theraot's user avatar
  • 27.2k
6 votes
Accepted

Any fast alternative to sine in GLSL?

ATI made an announcement that the sine / cosine instructions in their newest GPUs now requires only a single clock cycle... in 2004! Modern GPUs in fact have special function units specifically for ...
Philipp's user avatar
  • 120k
5 votes
Accepted

Is there a generic formula to determine the angle of deflection off of a rectangle?

The edges of your rectangle are just straight lines, so the angle of reflection is equal to the angle of incidence: Now, if this surface has its own angle, we can factor that in. Call the angle of ...
phlp's user avatar
  • 126
4 votes
Accepted

Math behind drawing one game object relative to another?

The way this is usually handled in games is something called a transformation hierarchy. Here objects are arranged in a parent-child relationship, where each object's position, rotation, etc is ...
DMGregory's user avatar
  • 135k
4 votes
Accepted

LibGDX How can I draw a line at a specific angle

you should use ShapeRenderer for this. In your draw loop ...
Sebastien Servouze's user avatar
4 votes

How can I correct an unwanted fisheye effect when drawing a scene with raycasting?

It looks like you're firing out your rays at evenly spaced angular intervals. ...
DMGregory's user avatar
  • 135k
4 votes

space map generation

You can scatter points using... uniform random coordinates (prone to uneven clusters and gaps) or a shaken or jittered grid, where you start with a regular lattice of points, then add a small ...
DMGregory's user avatar
  • 135k
3 votes
Accepted

Unity Mathf.Atan2 algorithm complexity

It doesn't make a lot of sense to talk about algorithmic complexity (in the big-O sense) for the way we use atan2 in game development. Our inputs are always one fixed size (32 bit floats for the Mathf ...
DMGregory's user avatar
  • 135k
3 votes

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

First of all, the FPS wouldn't be better. Most modern games are bottlenecked by the GPU mostly and are pretty OK with the CPU (often times only reaching a CPU usage of around 50% or less). Second, ...
Bálint's user avatar
  • 14.9k
3 votes
Accepted

When are oblique triangles used in game development?

Trigonometry is rarely applied directly in video game development. Allow me to explain what I mean by that: We will approach problems from a vector algebra standpoint first. And if you are struggling ...
Theraot's user avatar
  • 27.2k
3 votes
Accepted

Position Object always at the same distance of 2 other moving Objects?

My final approach has been using basic trigonometry: I have a and b I was just needing to calculate ...
fguillen's user avatar
  • 243
3 votes

Need help on finding the algorithm for getting the FlipX, Y and TextureRotation of my DirectionalAnimation class

See Asking and, because I know you've been linked it previously, The Good Asker. No-one is going to fix all of your code for free regardless of where you ask. It would be beneficial for us all to ...
spacer GIF's user avatar
3 votes
Accepted

How to overshoot with direction_to

In you code, you care computing the direction form the current position to the target every (physics) frame: ...
Theraot's user avatar
  • 27.2k
2 votes
Accepted

Turning x and y difference between two points into a projectile moving between them at a fixed speed

Your intuition is correct, the easiest way to do it would be to normalize your vector, and then rescale it using the Projectile.maxSpeed. If you need the angle for some reason, you can get the ...
Tom K's user avatar
  • 1,319
2 votes

Calculate target angle to a certain Vector

Working with angles can be really tricky, you have to properly define your coordinate system, the convention whether clockwise direction should be positive or negative and especially what range of ...
Maxkiel's user avatar
  • 46
2 votes

How to rotate a triangle to look at a point?

Given points A, B and C of a triangle, the normal of the triangle is the cross product AB×AC (or possibly AC×AB depending on the vertex order). If the point on the triangle is M and the point towards ...
sam hocevar's user avatar
  • 23.9k
2 votes
Accepted

Coordinates of the corners of a rectangle bridging two circles

This is pretty straightforward: ...
DMGregory's user avatar
  • 135k
2 votes

Find vector tangent to circle through a point

It's pretty easy with some trigonometry. Here's a hand drawn image of your problem: OTP angle is a right angle. Calculating l is done with the pythagorean ...
Bálint's user avatar
  • 14.9k
2 votes

LibGDX How can I draw a line at a specific angle

Accepted answer is good, but I couldn't use ShapeRenderer as it need to be used on closed batch. In that case you can use ShapeDrawer which is ShapeRenderer that can be used on open batch.
Elas's user avatar
  • 121
2 votes

How to make a sprite blink with Libgdx?

The blinking requires an alpha value that swings 0 and 1. The Sinus function swings between 1 and -1. So to solve the problem, the function has to be multiplied by 0.5 and be added to 0.5, so that the ...
purpule's user avatar
  • 113
2 votes

Getting an object to move in another objects direction

You're overcomplicating it. Let's say the object you want to move is at (x1; y1) and the player is at (x2; y2) The vector ...
Bálint's user avatar
  • 14.9k
2 votes

Move object at angle like a sine wave

Let's take a unit vector \$\vec u\$ in the direction we want to travel, and a vector perpendicular to it, \$\vec v\$: $$\vec u = \begin{bmatrix}cos \Theta\\sin \Theta\end{bmatrix}, \vec v = \begin{...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Aim/Scope Oscillation Algorithm

Using polar coordinates would do the trick. Here’s a graph of the function r=sin(2.3θ), with θ going from 0 to 2π: Given ...
Noah Witherspoon's user avatar
2 votes

Are there recursive variants for trigonometric functions to potentially improve performance?

Even if you could make something that's better on paper, than the already available sine and cosine functions, you'd have to essentially go down to the metal to make it useful. Some systems use the ...
Bálint's user avatar
  • 14.9k
2 votes
Accepted

How to panning camera on XZ axis with different angles

You can construct the camera's forward direction vector as: forward = normalize(lookAt - position) Then you can construct a vector pointing to the camera's right ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Convert GPS coordinates into Unity world space?

Presumably you considered just converting your angle and distance from polar coordinates into a Cartesian vector in the usual way? ...
DMGregory's user avatar
  • 135k
2 votes

How to find if a Ray intersects a Triangle Clockwise or Counter Clockwise

Assume the triangle's vertices are wound in the order A, B, C Form a normal to the triangle N = (B - A) x (C - A) Now you can detect whether your triangle is clockwise or counter-clockwise by the sign ...
DMGregory's user avatar
  • 135k

Only top scored, non community-wiki answers of a minimum length are eligible