How to Convert dir = (a.transform.position - b.transform.position).normalized; to Degrees ?


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.

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.