InverseTransformVector not changing frame of reference?
Hey! I'm fairly new to Unity, and I've been trying to code a script that turns its parent towards the mouse position:
void Update () {
var mouseAngle = transform.InverseTransformVector(Camera.main.ScreenToWorldPoint(Input.mousePosition));
Debug.Log(mouseAngle);
transform.localRotation = Quaternion.Euler(0, 0, Vector3.Angle(transform.position, mouseAngle));
}
But for some reason, Camera.main.ScreenToWorldPoint(Input.mousePosition) and transform.InverseTransformVector(Camera.main.ScreenToWorldPoint(Input.mousePosition)) return the same thing, even though the GameObject the script is attached to definitely has a parent to base its local frame of reference from. What am I doing wrong?
Thanks in advance for your time!
P.S: The reason i'm only rotating the z axis is because the game is in 2D.
Your answer
Follow this Question
Related Questions
how can my move a obect alon with the player 2 Answers
Set position flom RaycastHit.point 2 Answers
Rotate a GameObject smoothly towards mouse 1 Answer
Lerp Random Position - Within Original Vector3 1 Answer
How can I work with the opposite angle? 0 Answers