Created
June 7, 2012 16:32
-
-
Save justinbowes/2889905 to your computer and use it in GitHub Desktop.
chevyray's post translated from incomprehensible font
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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