kaihaider
Community Developer
- Joined
- May 18, 2010
- Messages
- 1,325
The gameobject method .IsFacing only returns true if you are looking directly at it.
So unless you're aiming a sniper rifle, you'll probably want to use something like this:
So unless you're aiming a sniper rifle, you'll probably want to use something like this:
Code:
public static bool IsFacing(GameObject o) {
float headingTowardsTarget= MathEx.NormalizeRadian(MathHelper.CalculateHeading(Core.Me.Location, o.Location) + (float)Math.PI);
float d = Math.Abs(MathEx.NormalizeRadian(Core.Me.Heading - headingTowardsTarget));
if (d > Math.PI) d = Math.Abs(d - 2 * (float)Math.PI);
//Logging.Write("Differance: " + d);
return d < 0.785f;
}
Last edited: