Trying to clamp a second position to 45 degrees in 2d space
I have a vector2 origin position. I have a secondary position, which I have already determined the distance along the x and y planes from the original position (for other logic).
So I have used them to determine the angle from the original position, looking for 45-degree angles (within a variance). What I want to do is return the average position at exactly 45 degrees of the secondary position.
Just a snippet of the code below.
//calculate angle of mouse position from buildpoint
float radAngle = Mathf.Atan2(xDistance, yDistance);
float angle = Mathf.Rad2Deg * radAngle;
//check if angle is 45 degrees within tolerance
if (angle > 41 && angle < 49)
{
This is already stretching my math abilities (and its 11pm and my eyes feel like they are going to pop lol). But just looking for some ideas on a) if I can approach this logic in a better way and b) how to determine that clamped 45 degree angle of the second position?
Thanks!
Comment