I have Vector2 position1 and Vector2 position2. How can I get the angle between them?
I managed to find method Vector3.SignedAngle(targetDir, forward, Vector3.up) but it returns floats while I need degrees 0…360. It’s not radians, what numbers are they? How can I convert them to degrees?
Vector3.SignedAngle returns degrees, although it’s going to return them in the interval of -180 to 180, not 0 to 360. There is probably something wrong with your arguments or how you calculated them.
The smaller of the two possible angles between the two vectors is returned, therefore the result will never be greater than 180 degrees or smaller than -180 degrees
But a bit down, in a sample
if (angle < -5.0F)
print("turn left");
else if (angle > 5.0F)
print("turn right");
else
print("forward");
This is what I get usually, numbers 1.0f, 5.0f, 10.0f. Why I can’t get degrees?
The C# language doesn’t have any kind of “degrees” data type, if that’s what you’re confused about.
Pretty sure no programming language does, since they’re just numbers at the end of the day.
I’m not sure what “the angle between two points” means. That doesn’t really make sense. Could you maybe draw a picture of what you’re talking about? Why would you need an angle to draw a straight line?
Generally you need 3 points to calculate an “angle”, treating two of them as “directions” away from a third point. The third point is assumed to be the origin (0, 0) for the Vector2.Angle and Vector2.SignedAngle methods.
I got lost, I thought I was near the answer, but failed. Here is the picture of problem. I have two dots (x,y) and (x1, y1) and I need I draw red line between them. Actually red line is a thick image and I need just specify Z angle of it and it will be nicely rotated. Any idea how to do it?