Skip to content

Instantly share code, notes, and snippets.

@justinbowes
Created June 7, 2012 16:32
Show Gist options
  • Save justinbowes/2889905 to your computer and use it in GitHub Desktop.
Save justinbowes/2889905 to your computer and use it in GitHub Desktop.
chevyray's post translated from incomprehensible font
private function pushOutUnits(elastic:Number):void
{
for (var i:int = 0; i < units.length - 1; i++)
{
for (var j:int = i + 1; j < units.length; j++)
{
push.x = units[i].x - units[j].x;
push.y = units[i].y - units[j].y;
var d:number = push.length;
var r:number = units[i].radius + units[j].radius;
if (d < r)
{
// the part @ChevyRay missed. Have to move out by (r - d) / 2 not just d / 2!
push.normalize((r - d) * 0.5 * elastic);
units[i].x += push.x;
units[i].y += push.y;
units[j].x += push.x;
units[j].y += push.y;
units[i].acc = units[j].acc;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment