Skip to content

Instantly share code, notes, and snippets.

@DfKimera
Created February 4, 2013 00:41
Show Gist options
  • Select an option

  • Save DfKimera/4704407 to your computer and use it in GitHub Desktop.

Select an option

Save DfKimera/4704407 to your computer and use it in GitHub Desktop.
var dist:int = unit.distanceTo(unit.targetNode);
var minDist:int = moveSpeed;
if(dist < minDist) {
unit.targetNode = new FlxPoint();
unit.currentTask = Unit.TASK_IDLE;
} else {
var angleRad:Number = Math.atan2(unit.targetNode.y - unit.y, unit.targetNode.x - unit.x);
var dx:int = Math.cos(angleRad) * moveSpeed;
var dy:int = Math.sin(angleRad) * moveSpeed;
unit.x += dx;
unit.y += dy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment