/// <summary> /// Returns the angle to turn to face particular coordinates. /// </summary> public static double AngleToCoordinates(this IWalker a, double x, double y) { double distToTarget = a.DistanceFrom(x, y); double curHeading = (90.0 - a.Heading).ToRadians(); // relative to the x-axis double xC = a.Position.X + distToTarget * Math.Cos(curHeading); double yC = a.Position.Y + -distToTarget *Math.Sin(curHeading); // let the built-in vector math sort it all out :-). Vector vHeading = new Vector(a.Position.X - xC, a.Position.Y - yC); Vector vTarget = new Vector(a.Position.X - x, a.Position.Y - y); return(Vector.AngleBetween(vHeading, vTarget).MinimumAngle()); }
/// <summary>Calculates how many degrees a zombie/human should turn to face a particular thing</summary> /// <returns>The angle to turn. A negative number means a left turn, a positive number means a right turn.</returns> public static double AngleTo(this IWalker a, ITakeSpace b) { /* * Thanks to Chris for inspiring me to fix this; my version didn't work, and his version didn't work either. * (Atleast for what Yusuf was wanting them to do. XD ) * * GreedyHuman fails on the Plentiful map with either implementation. * On the other hand, this version works well, gives left-or-right turns, and it's short & clean too. */ double distToTarget = a.DistanceFrom(b); double curHeading = (90.0 - a.Heading).ToRadians(); // relative to the x-axis // the heading intersects a circle with radius /distAB/ at some point, call it C. Find that point of intersection. // x = xA + r cos (heading) // y = yA + r sin (heading) double xC = a.Position.X + distToTarget * Math.Cos(curHeading); double yC = a.Position.Y + -distToTarget *Math.Sin(curHeading); // let the built-in vector math sort it all out :-). Vector vHeading = new Vector(a.Position.X - xC, a.Position.Y - yC); Vector vTarget = new Vector(a.Position.X - b.Position.X, a.Position.Y - b.Position.Y); return(Vector.AngleBetween(vHeading, vTarget).MinimumAngle()); }
/// <summary> /// Returns true if the player is close enough to interact with (e.g., bite or take socks from) the specified thing on the map /// </summary> public static bool IsCloseEnoughToInteractWith(this IWalker a, ITakeSpace b) { return(a.DistanceFrom(b) - a.Radius - b.Radius <= WorldConstants.InteractionDistance); }