- Home /
How to Convert dir = (a.transform.position - b.transform.position).normalized; to Degrees ?
HI,
I need to get (x,y,z) rotations for my target,
I have target and I need to go there. so I can rotate my object to that direction by,
transform.rotation = (a.transform.position - b.transform.position).normalized;
but I don't want to rotate that object with this, I need it's (x,y,z) rotation values in degrees for turn my object with another script. please help if you know. Think that object as car. and I need to tell my car your target is 84deg in x and 20deg in y and 10deg in z. actually it turn based those angles and I need it that way.
I'm also try this,
vector3 dir = (a.transform.position - b.transform.position).normalized; float myX = dir.x Mathf.Rad2Deg; loat myY = dir.y Mathf.Rad2Deg; loat myZ = dir.z * Mathf.Rad2Deg;
but it's not working.
Answer by bdubbert · Sep 23, 2021 at 03:23 PM
To get the rotation between two vectors use Quaternion.FromToRotation. Then you can pull out the euler angles from that. If you want the rotation in world space, use
Vector3 myRotationAngles = Quaternion.FromToRotation(Vector3.forward, dir).eulerAngles;
If you just want the rotation between the direction a is facing and the direction between the two objects, use
Vector3 myRotationAngles = Quaternion.FromToRotation(a.transform.forward, dir).eulerAngles;
Make sure you are using the euler angles from quaternions and not directly checking the x/y/z of the quaternion.
Your answer
Follow this Question
Related Questions
Understanding Space.World and Space.Self: Character changing movement direction 1 Answer
Vector3.SignedAngle wrong direction when crossing the 0 point 1 Answer
Objects Rotation to modify Objects transform velocity/Direction of travel 1 Answer
Move object forward in relation to the player 1 Answer
How to make player move the way the joystick is moving [Example Shown] 1 Answer