# How to find the direction an object is flying in?

I have a golf ball that is spinning on all the different axis and I need to find out which angle it is heading in on the Y axis. Transform.forward doesn’t work because it is spinning.

Hello.

[Edited] : Pangamini comment is correct, is a better (less cpu cost) way.

Maybe there is some command or fucntion to know it.

But if you dont find any, you can always make a “trick”:

In a script, during the same frame…:

Create a emptyobject, child of the ball with localposition and localrotation of 0.

Move this emptyobjc in Y axis of its local coords.
Then, unparent it from the ball.

Then calculate the vector (emptyobj position - ball position).

This vector is the Y direction of the ball.

Bye!

Ah now I understand the problem
By ‘angle on the Y axis’, you mean, like, the azimuth.
First, the rotation of the ball has nothing to do with its movement. The ball has a velocity (either from rigidbody, or from your own script), which I will assume is a world-oriented Vector3.
If that is the case, and what you want to calculate is the azimuth, then you need to:

1. Take the X and Z elements of the velocity (the Y element doesn’t affect the azimuth, right?)
2. Feed it to the Mathf.Atan2. It will calculate an angle of a vector from the X+ axis in CCW direction. See the docs for that function. The result is in radians, make sure you convert to the units you need.