I’m trying to display a direction after the object applies it’s rotations set by a tween. It rotates correctly, but I can’t get the direction to properly display in the gizmos.
The transform eulerAngles is the same as local in this case. It’s (45f, 45f, 0f).
_rotTarget = new Vector3(90f, 90f, 0f);
Quaternion q = Quaternion.identity;
q.eulerAngles = _rotTarget + transform.eulerAngles;
Vector3 dir = q * Vector3.forward;
CustomExtensions.ForGizmo(transform.position, dir, Color.yellow);
It should have the arrow pointing down relative to the object (pic 2), but it’s displaying another dir instead (pic 1).
Pic
Euler angles are terrible. They’re subject to bizarre math problems like gimbal lock, and are really suitable for exactly one purpose: allowing a human to type in rotation values. Use Quaternion functions to manipulate rotations directly.
If you’re just looking for the transform’s down vector specifically, you can easily do this with:
Vector3 cubeDown = transform.rotation * Vector3.down;
Or if you need the rotation for that, you can use .AngleAxis to rotate 90 degrees around the cube’s X axis: (might be supposed to be -90, I’m never sure)
Quaternion cubeDownRotation = transform.rotation * Quaternion.AngleAxis(90f, transform.right);
The rotation isn’t always down. It’s just wherever the tween is set to rotate to. DOTween adds to the local rotation using a vector.
The goal is just to display the direction of the accumulated angle in local space.
I thought since we’re adding (45f, 45f, 0f) to (90f, 90f, 0f), we’ll get a rotation of (135f, 135f, 0f) of Vector3.forward. Which should point to transform.down in this case, but it doesn’t.
Here’s another example. transform.eulerAngles = (45f, 0f, 0f), and _rotTarget = (0f, 90f, 0f). Which should return figure 01’s direction (blue cube), but instead it gives me figure 02’s direction(yellow arrow). I’m confused as to how I’d get the new direction using accumulative rotation.
Figure 01
Figure 02