Skip to main content
88 votes
Accepted

I'm rotating an object on two axes, so why does it keep twisting around the third axis?

No this isn't an engine bug or an artifact of a particular rotation representation (those can happen too, but this effect applies to every system that represents rotations, quaternions included). You'...
DMGregory's user avatar
  • 135k
35 votes
Accepted

How can I rotate an object based on another's offset to it?

The answer is actually pretty easy if you do the math. You have a fixed distance of Y and a variable distance of X (See Picture 1). You need to find out the angle between Z and X and turn your turret ...
John Hamilton's user avatar
35 votes
Accepted

How to make sure spinning objects hit a target with the right end?

Fake it Look at the video you linked, watch it in slow motion... eh, what is that? The camera jumps at the end, and the knife is already in the helmet of the target. Just fake it. Once the distance ...
Theraot's user avatar
  • 27.2k
24 votes
Accepted

Using Quaternions: What can I do with them? (without the maths)

Multiplication At least in terms of Unity's implementation of Quaternions, the multiplication order described in the question is not correct. This is important because 3D rotation is not commutative. ...
DMGregory's user avatar
  • 135k
20 votes

How can I rotate pixel art sprites without the aesthetics getting ruined?

Have a look at RotSprite. RotSprite is a scaling and rotation algorithm for sprites developed by Xenowhirl. It produces far fewer artifacts than nearest-neighbor rotation algorithms, and like EPX, it ...
Rudey's user avatar
  • 453
17 votes
Accepted

How can I rotate pixel art sprites without the aesthetics getting ruined?

Automatic rotation of pixel art by other angles than 90° usually goes wrong. If you want to maintain the pixel-art aesthetics you usually won't get around redrawing your art in each angle. If you use ...
Philipp's user avatar
  • 120k
15 votes

Using Quaternions: What can I do with them? (without the maths)

Where's the dot product used? In Unity, one of the most common users of the dot product is whenever you check if two quaternions are equal via == or ...
Luke Briggs's user avatar
14 votes

How to make sure spinning objects hit a target with the right end?

If you know ahead of time where the knife will land - like in those kill cam footage, which is most definitely produced after-the-fact - just calculate the right rotation speed based on flight ...
congusbongus's user avatar
  • 14.8k
14 votes

How to make sure spinning objects hit a target with the right end?

Calculate the straight line distance to target. Each Frame set the angle of the knife to be 2PI*(remainingStraightLineDistance)/(originalStraightLineDistance)*DesiredNumRotations. The spin ratio will ...
Tim B's user avatar
  • 556
10 votes
Accepted

Unity: transform.LookAt(target) not "looking at" target?

The Problem: Your eyes default rotation makes them look to the negative X axis. However, Transform.LookAt() rotates the transform, so that the Transform.forward looks at the target. The Transform....
Chillersanim's user avatar
7 votes
Accepted

Rotate from Current Rotation to Another using Angular Velocity

"maybe due to the gimbal nature of Vector3 for angular velocity" ...using Vector3 for angular velocity does not entail gimbals, but converting it to Euler angles does. Angular velocity is not an ...
DMGregory's user avatar
  • 135k
7 votes
Accepted

Converting a quaternion in a right to left handed coordinate system

A quaternion can be thought of as an angle-axis representation: quaternion.xyz = sin(angle/2) * axis.xyz quaternion.w = cos(angle/2) So, converting them between ...
DMGregory's user avatar
  • 135k
6 votes

In LibGDX, how might I make an object orbit around a position?

If you wish for an object to orbit around a specified point in two dimensional space, you want to use some trigonometric functions. Here is an example method to calculate an objects position in an ...
Aidan Lovelace's user avatar
6 votes
Accepted

Understanding SpriteBatch.Draw overload XNA

Basic explaination about the method with regards to positioning, scaling and rotating: This draws a sprite with myTexture with the topleft corner on 100,200: <...
Felsir's user avatar
  • 4,067
6 votes
Accepted

Direction vector to quaternion

From http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ ...
Bram's user avatar
  • 3,719
6 votes
Accepted

Rotate an object to face a point with glm::lookAt

Because the lookAt function is to position the camera to look at an object (not for an object to look at another object) and the way 3D cameras work is that ...
Stephane Hockenhull's user avatar
6 votes
Accepted

Unity - moving an object around a radius

You need to put a cap on how big rotationAngle is allowed to be. Right now, as the difference between the mouse and the "player" grows larger, your "player" ...
Draco18s no longer trusts SE'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

Combining Quaternion Rotations

Multiplying two quaternions gives you a quaternion equivalent to performing the two rotations they represent in sequence. ...
DMGregory's user avatar
  • 135k
5 votes
Accepted

Extract a rotation matrix given a camera direction (vector) and a up vector for the camera?

NOTE: Edited because it was likely too verbose (source). A rotation matrix actually always defines an orthonormal basis. What this means is each column defines one of your original axes in its ...
WafflesTasty's user avatar
5 votes
Accepted

How to make one 3D object face another?

There are a couple ways to do this, but here's one way to do it. We can generate a rotation matrix by storing 3 normalized vectors as columns for a 3x3 matrix. The first column will be normalized ...
Tom K's user avatar
  • 1,319
5 votes

Convert quaternion to a different coordinate system

Summarizing your two coordinate spaces: ...
DMGregory's user avatar
  • 135k
5 votes

Unity Quaternion.LookRotation meaning

Quaternion.LookRotation(forward, up) constructs an orientation quaternion that... rotates an object's local z+ axis (0, 0, 1) — the blue arrow on its local ...
DMGregory's user avatar
  • 135k
5 votes
Accepted

Why use gimbals?

If I understand you correctly, by local rotation you mean something like this: ...
DMGregory's user avatar
  • 135k
5 votes
Accepted

Is there any way to keep the applied torques in the old planes, even if the ship's local plane has rotated?

First, your interpretation of what's happening in Unity is not accurate. When you apply your roll torque, the axis of the continuing yaw drift does not shift to match the object's new local XZ plane, ...
DMGregory's user avatar
  • 135k
5 votes

Why rotating an object only on its local X axis result in sudden 180 degrees changes in Y and Z axis rotation values

The thing to remember about Euler angles is that they're a fiction the engine generates on demand for our sake. They're not the ground truth of how rotation is stored inside the engine (that uses ...
DMGregory's user avatar
  • 135k
5 votes
Accepted

Handedness of 2D coordinate systems

It entirely depends on what you want to do with it and both have reasons why they exist. The one where the top left corner is the origin and the positive xes point away from them are based on the way ...
Bálint's user avatar
  • 14.9k
5 votes
Accepted

Unity3d: Find which gameObject is in front

You can check simple ahead/behind relationships using the dot product: ...
DMGregory's user avatar
  • 135k
5 votes

Does gimbal lock occur only when a combination of local and world rotation axis are used?

Gimbal lock occurs when your internal structure for storing/composing rotations uses a gimbal model: Image via Wikipedia, attributed: "By Lookang many thanks to Fu-Kwun Hwang and author of Easy ...
DMGregory's user avatar
  • 135k

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