I'm trying to test some code to create Vector2 from its angle and its distance from the player position. I've looked up online how to do this and found the Vector2.Angle function to get the angle between two vectors, and the Vector2.Distance function to find the distance between two vectors, and I thought that I would be able to recreate the original (check_points[i]) Vector using these values, but when I run this code this is what I get (the white lines are from position to check_points[i], and the red lines are from position to other, which is the vector I'm trying to create from the values):
I would have expected the red and white lines to be the same, how can I make them this way?
float angle = Vector2.Angle(position, check_points[i]) * Mathf.Deg2Rad;
float dist = Vector2.Distance(position, check_points[i]);
Vector2 other = new Vector2(Mathf.Cos(angle) * dist, Mathf.Sin(angle) * dist);
Debug.DrawLine(position, check_points[i], Color.white);
Debug.DrawLine(position, other, Color.red);
The point of this is to track the corners of obstacles so I can generate a mesh from the triangles made between the corners and the player, to do line of sight checking. I've previously gotten it to work just casting a ray out for every degree of rotation (0-360), but I've read this tutorial and am trying to implement corner tracking to get it to look smoother: https://ncase.me/sight-and-light/


vertex[i] = (cos(angle) * maxViewDistance, sin(angle) * maxViewDistance)- Tom Tetlaw0,0,0basically results in a vector without a direction and magnitude 0 ... so I guess it should be undefined what an angle between e.g.0,0,0and1,2,3is ... you would need to get an angle between a valid direction vector and your position instead like e.g.Vector3.Angle(Vector3.right, check_points[i] - position)and then later doVector2 other = position + new Vector2(Mathf.Cos(angle) * dist, Mathf.Sin(angle) * dist);or something like that - derHugo