85 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
  • 134k
46 votes
Accepted

What is the standard practice for animating motion -- move character or not move character?

Animations in which the character translates away from the origin are said to contain "Root Motion" - because the root bone moves. This allows the animator to directly author subtle non-...
DMGregory's user avatar
  • 134k
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
  • 134k
18 votes

How does a 4x4 matrix represent an object in space and matrix lore?

How is Matrix Multiplication a Transformation? A matrix is just a big grid of numbers with rules that define how we can multiply it with other grids or lists of numbers. In games, we usually want to ...
DMGregory's user avatar
  • 134k
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
11 votes

How and when do the model to world, world to view, et cetera multiplications happen?

Think about it logically: What is your goal when you render something? To display it on the screen! What are the constraints? The model must be visible to the camera (i.e. in the view frustum, not ...
Dan's user avatar
  • 501
9 votes
Accepted

Do matrix manipulations for 3D graphics ever produce singular matrices?

The simplest way this can happen is if you shrink an object until its local scale in one or more axes is 0 (flattening it to a plane, line, or point). You can avoid this by disallowing scales below a ...
DMGregory's user avatar
  • 134k
8 votes
Accepted

In Unity, how to get reference of descendant?

Yes, transform.Find(name) will only look in the direct children of the current transform. But if you want to get a child deeper in the hierarchy, you can use ...
Philipp's user avatar
  • 119k
6 votes
Accepted

Stop movement if transform.position.y == 0

Because the Y position is never EXACTLY 0. Its for example 5.5 next frame: 4.3 next frame: 3.1 next frame: 1.9 next frame: 0.7 next frame: -0.5 change the if to ...
OC_RaizW's user avatar
  • 1,460
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

Detect transform from detection of QR code?

Deriving the transformation Note that the transformation of the QR code captured by the camera is a perspective transformation. As such, no amount of affine transformation can emulate it (translating,...
Theraot's user avatar
  • 26.2k
5 votes

Calculate vector3 global point projecting it in local space using Unity and C#?

Let's say you have a trasnformed coordinate system defined by a quaternion rotation, and vector3 position. For example, the ...
Theraot's user avatar
  • 26.2k
5 votes
Accepted

How to mirror/reflect/flip a 4D transformation matrix

To get a transformation matrix equivalent to the one you have, but reflected across a major axis you can compose it (multiply it by) a reflection matrix. That is, if you have your input matrix M and ...
Theraot's user avatar
  • 26.2k
5 votes
Accepted

How to convert a 4x4 matrix transformation to another coordinate system?

This is as easy as writing your old coordinates in terms of the new ones. We want +x to map to +x (1, 0, 0) We want +y to map to +z (0, 0, 1) We want +z to map to -y (0, -1, 0) We want the fourth, ...
DMGregory's user avatar
  • 134k
4 votes

Fastest way to neutralize scale in the transform matrix?

Assuming your matrix multiplication follows the convention... M * v = (T * R * S) * v (where M is your composed matrix, ...
DMGregory's user avatar
  • 134k
4 votes

Make one object rotate to face another object in 2D

I can see this question is old, but it's a fairly common issue worth a standard answer. Quaternion.LookRotation gives us a convenient way to say "point this way" but the problem is that it wants to ...
DMGregory's user avatar
  • 134k
4 votes
Accepted

How to get an game object to instantiate lower than where It's created?

ally = (GameObject) ...is a syntax error. You need to comment this line just like you did the one below it. The problem is on that line, but because it's so ...
Engineer's user avatar
  • 29.5k
4 votes
Accepted

Unity / Rotate a point around an arbitrary axis and anchor

The concept of a "rotation" is represented by a Quaternion. These are built into Unity and there's no need for you to understand the math in that link you posted. To create a rotation from an angle &...
Foggzie's user avatar
  • 1,222
4 votes
Accepted

LookRotation() make X axis face the target instead of Z

I've answered a few flavours of this before. The basic idea is to chain together two rotations: one that takes the axes you want to align and points them along z+ and y+ respectively, and then the ...
DMGregory's user avatar
  • 134k
4 votes
Accepted

Why does the Debug.DrawRay return these weird lines

You're drawing Rays, not Lines. This means that the second parameter is a direction not a point in space. https://docs.unity3d.com/ScriptReference/Debug.DrawRay.html Draws a line from ...
Draco18s no longer trusts SE's user avatar
4 votes
Accepted

Rotate object such that a child object is facing a target (3D)

Think about the problem backwards, how would we rotate C around A so that it lines up with B. If we can solve this problem, we just need to rotate A by the same amount, but in the opposite direction. ...
Reuben Crimp's user avatar
4 votes
Accepted

What methods can be used to rotate a tiled structure?

It sounds like you might be looking for Rotation by Shearing, or Alan Paeth's "A Fast Algorithm for General Raster Rotation" I first learned about this technique via the excellent DataGenetics blog. ...
DMGregory's user avatar
  • 134k
4 votes
Accepted

Unity RectTransformUtility.ScreenPointToLocalPointInRectangle

Preface This question starts with a small geometry problem. You have two different planes which may or may not be parallel. 1) Your screen space. This is the actual screen coordinates your computer ...
DrewAtWork's user avatar
4 votes
Accepted

Efficiently calculate 2d world position based on parent(s) recursively

The way this is typically handled is with a dirty flag. Each object stores both its current local transformation/bounds, and a net transformation/bounds according to its whole parent hierarchy (eg. a ...
DMGregory's user avatar
  • 134k
4 votes
Accepted

What does the Node2D transform property do?

In games, a "transform" refers to how an object is positioned, oriented, or scaled within the game world. To move an object, to rotate an object, or to squash and stretch an object are all forms of "...
DMGregory's user avatar
  • 134k
4 votes
Accepted

In practice, is it better to store Euler angles or store three vectors represent as "front/right/up"?

So in practice, is it better to store Euler angles or vectors for axis? This totally depends on your requirements. In general, object orientations (rotations) can be represented in several ways: A ...
wychmaster's user avatar
4 votes

In practice, is it better to store Euler angles or store three vectors represent as "front/right/up"?

Most 3D engines do neither of these things. Euler angle rotations are very messy to try to compose. If you have one object rotated on all three axes, and you want to rotate it about an arbitrary ...
DMGregory's user avatar
  • 134k

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