Other
LookRotation() * Vector to rotate a vector?
Context: I'm having trouble using LookRotation() to find the same result as transform.right. The following code draws 3 gizmos (forward, right, and up) in the local space of a cube, and I'm trying to accomplish this using a convoluted method, which is to apply a LookRotation() Quaternion-rotation on Vector3.right and Vector3.up, to find their local space equivalent.
However, only the conversion of Vector3.forward has been successful.
Can anyone help me understand why this is not working? Greatly appreciated.
using UnityEngine;
public class DirectionalOffsetTests : MonoBehaviour
{
Vector3 myPos => transform.position;
private void OnDrawGizmosSelected()
{
Vector3 fwd = transform.forward;
//These are perfectly right
Debug.DrawRay(myPos, transform.forward, Color.blue);
Debug.DrawRay(myPos, transform.right, Color.red);
Debug.DrawRay(myPos, transform.up, Color.green);
Vector3 up = Quaternion.Euler(0f, 0f, 90f) * fwd.normalized;
Vector3 localForward = Quaternion.LookRotation(fwd, up) * Vector3.forward;
Vector3 localRight = Quaternion.LookRotation(fwd, up) * Vector3.right;
Vector3 localUp = Quaternion.LookRotation(fwd, up) * Vector3.up;
Gizmos.color = Color.blue;
Gizmos.DrawSphere(myPos + localForward, 0.2f);
Gizmos.color = Color.red;
Gizmos.DrawSphere(myPos + localRight, 0.2f);
Gizmos.color = Color.green;
Gizmos.DrawSphere(myPos + localUp, 0.2f);
}
}
Follow this Question
Related Questions
Problem with Quaternion and Euler Angles 0 Answers
How to make the front, left, right, or the back of a gameobject look at a target? 1 Answer
Updating Current rotation data on firstpersonlook from load game file 0 Answers
Quaternion.Slerp not working 1 Answer
How to Rotate player on Y Axis using Mouse position, but also Clamp the rotation distance? 0 Answers