- Home /

# Need a little help with quick angle equation

My brain's frazzled, can anyone help? For some reason I can't think of the most efficient way to do the following:

Imagine the world is a flat plane at Y=0. An object A is somewhere on this plane, facing in any direction along the plane. So its position is (anything,0,anything) and euler angles are (0,anything,0) Object B is somewhere else on the plane, direction irrelevant.

I want to work out the relative Y-axis angle from A to B. Assume I don't have access to transforms, only their positions and A's euler angles. So the answer should be a float giving what should be added to A's euler angle Y-axis in order to face B.

**Answer** by poncho
·
Feb 17, 2011 at 05:56 PM

you have A position x and z and also B position x and z, with this use the angle form as it was on x and y axis will be like

float angle = 180/Mathf.PI * Mathf.Atan2(A.position.z-B.position.z, A.position.z-B.position.z);

this angle is respect the vector (1,0,0) means the right from the front is the 0 from above then having the angle between the objects add the difference between the actual y rotation and the respective angle from the objects.

hope this is the answer you are looking for

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.