IsWithinDist

From scripting
Jump to: navigation, search
global proc int IsWithinDist(string $Obj1, string $Obj2, float $Dist) {
       //Author Nick Pisca 0001d 2009
	float $B1[] = `getAttr($Obj1+".translate")`;
	vector $B1Vec = <<$B1[0], $B1[1], $B1[2]>>;
	float $B2[] = `getAttr($Obj2+".translate")`;
	vector $B2Vec = <<$B2[0], $B2[1], $B2[2]>>;
	vector $BDiff = $B1Vec - $B2Vec;
	float $BDist = mag($BDiff);
	int $Win = 0;
	if ($BDist <= $Dist) {
		$Win = 1;
	}
	return $Win;
}


More information on vector declarations and calculations, read pages 12-15 in YSYT.