Skip to content

Instantly share code, notes, and snippets.

@phrohdoh
Created January 9, 2014 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phrohdoh/8337871 to your computer and use it in GitHub Desktop.
Save phrohdoh/8337871 to your computer and use it in GitHub Desktop.
A function written before realizing OpenRA has FindActorsInCircle.
bool IsInRangeOf(Actor actorInQuestion, Actor sourceActor, bool use3D = false)
{
// convert distance (px -> cells)
var distX = (sourceActor.Location.CenterPosition.X - actorInQuestion.Location.CenterPosition.X) / 1024;
var distY = (sourceActor.Location.CenterPosition.Y - actorInQuestion.Location.CenterPosition.Y) / 1024;
var distZ = (sourceActor.Location.CenterPosition.Z - actorInQuestion.Location.CenterPosition.Z) / 1024;
// convert Info.Range (px -> cells)
var range = (Info.Range * 1024);
if (use3D)
if (distX < range && distY < range && distZ < range)
return true;
if (distX < range && distY < range)
return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment