Hot answers tagged angles
14
I believe your intuition was correct, just not your formula.
atan(4 / 3) = 53.1301024 degrees
This ratio can be useful because it forms a Pythagorean triangle, meaning that the length of the diagonal is an exact integer value.
6
You do not need to know the angle, because the difference in X and Y already gives you the desired orientation of the enemy. The only thing that remains to be done is normalise that direction vector (if possible -- otherwise it means the player and the enemy are exactly at the same position), and multiply it by the enemy’s speed:
dx = player_x - enemy_x;
dy ...
6
Two parts: 1. coordinate systems for angles can be...finicky. 2. You don't really need degrees for anything, with the possible exception of outputting their value to the user interface.
Coordinate system angles
So you want an angle from "North", and judging from your example math, that means the -Y direction (in sprite coordinates with the origin in the ...
4
GLM's rotation function uses Euler's rotation theorem, which implies that any rotation or sequence of rotations of a rigid body in a three-dimensional space is equivalent to a pure rotation about a single fixed axis.
However consecutive calls to GLMs rotate function just multiply the rotation so rotating a rigid body by Yaw, Pitch, Roll is as simple as ...
3
The industry standard for first-person view simulation in most shooters is to have character models and animations distinct from those used for third-person view. There are several reasons for this:
The player has a much smaller field of view upon the world than a real person in the character's situation would, and he lacks other forms of input such as ...
3
double angle = Math.atan2(y,x); // Note: keeping angle in radians for cos & sin.
dx = enemy.speed * Math.cos( angle );
dy = enemy.speed * Math.sin( angle );
This will work fine with negative angles.
See also: What are atan and atan2 used for in games?
3
When working with floating point values it's usually not a good idea to use the comparison operator, as even slight inaccuracies will result in inequality. That's why a comparison of floats usually incorporates some sort of "epsilon".. a margin of error.
Example:
if(Math.abs(floatA - floatB) <= epsilon){
// equal
}
Epsilon is the desired ...
3
Let b be the angle between vectors p1p2 and p1p3. Its value can be computed as:
b = pi - atan2(p1p3.y, p1p3.x)
The angle between p1p4 and p1p3 is b-a. Since p1p3p4 is a right-angled triangle, we know that cos(b-a) is the distance p1p4 divided by the distance p1p3.
The answer is then:
a = pi - atan2(p1p3.y, p1p3.x) - acos(r / length(p1p3))
Replacing ...
3
First figure out the direction based on where the particle is in reference to where it came from (the explosion). Then you take the arc-tangent of that to get the angle.
Vector2 direction = particlePosition - explosionPosition;
float angle = Math.Atan2(direction.Y, direction.X);
2
EDIT: The answer is now correct, you had to add 360 in case of diff negative
You just have to look at the difference between the two angles. It it is between 0 and 180, you turn left (anticlockwise), otherwise right.
int FindTurnSide(int current, int target)
{
int diff = target - current;
if(diff < 0)
diff += 360;
if(diff ...
2
Normally I store all objects as 4x4 Matrices (you could do 3x3 but easier for me just to have 1 class) instead of translating back and forth between a 4x4 and 3 sets of vector3s (Translation, Rotation, Scale). Euler angles are notoriously difficult to deal with in certain scenarios so I would recommend using Quaternions if you really want to store the ...
2
The camera angle used by most "isometric" games is actually 30 degrees (a true isometric view where the x, y, and z axis have the same length is 35.264 degrees). The reason for this angle is so that the width of the tile ends up being twice its height. This way you can get an even 2:1 ratio when drawing the diagonals so the tiles line up neatly without any ...
1
The function takes angles and calculates vectors that point in directions relative to angles.
For angles, and the operations sin cos and tangent, you'll want to look up trigonometry.
Multiplying an angle in degrees by M_PI*2 / 360 converts degrees to radians. (M_PI = 3.14).
forward is a vector that points in the direction that the angles form to create ...
1
It just computes a (slightly wacky, because of Quake's "entity pitches are negative" thing) 3x3 rotation matrix, with each column (or row, depending on your preference) being one of the forward/right/up vectors. This can then be used to position various objects/effects/etc relative to the view; Quake uses it for pushing muzzleflashes slightly forwards and ...
1
The angles used to build a rotation for each of the three axes are known as Tait-Bryan angles (often confused with Euler angles).
Wikipedia has all the formulas you need to convert Euler or Tait-Bryan angles into a rotation matrix.
Here is some code to build a rotation matrix from three Tait-Bryan angles and the order of the rotations:
/* i, j and k are ...
Only top voted, non community-wiki answers of a minimum length are eligible
