what is wrong with my Vector3.Angle() code?

when this code is run, the variable mydirection says 90 degrees, instead of the 0 degrees that it should show. Why is this? I have already spent days hitting my head against the wall, so any input would be great.

AssemblyCSharp.locData[] myList = new AssemblyCSharp.locData[7];

//A list of an object called locData

// x   z   
AssemblyCSharp.locData holla = new AssemblyCSharp.locData(7.57,-.84);
myList[0] = holla;

//the part below is where I think the problem is, did I misuse the Vector3.Angle() method? 

mydirection = Vector3.Angle((new Vector3((float)myList[stop].getx(),0f,(float)myList[stop].getz())-transform.position),transform.up);

Why would you expect 0?

Your vector, from which you subtract your position, is only in the x-z-plane, so it’s naturally exactly 90° to the upvector which is (0, 1, 0) for a nonrotated object.

I guess direction is a float? What is it supposed to store? The direction as angle? if so you’re doing it totally wrong :wink: Are you sure that you actually need the angle? Usually you work with vectors all the time.

Vector3.Angle always returns a positive angle since there is no clear sign between two arbitrary vectors in 3D space. You might want to use Mathf.Atan2:

Vector3 dir = new Vector3((float)myList[stop].getx(),0f,(float)myList[stop].getz()) - transform.position;

float angle = Mathf.Atan2(dir.z, dir.x) * Mathf.Rad2Deg;

ps: I’m a bit confused about your custom class “locData”. Besides that the type starts with a lowercase letter, it seems strange that you have to cast it to float and that you have to query x and z seperately… Any insight what this class (or struct?) is used for?

Is the containing namespace / class really called “AssemblyCSharp” ?