GameEntities.PlayerIntellect.FindFreePositionForUnit C# (CSharp) Method

FindFreePositionForUnit() private method

private FindFreePositionForUnit ( Unit unit, Vec3 center ) : Vec3
unit Unit
center Vec3
return Vec3
        Vec3 FindFreePositionForUnit( Unit unit, Vec3 center )
        {
            Vec3 volumeSize = unit.MapBounds.GetSize() + new Vec3( 2, 2, 0 );

            for( float zOffset = 0; ; zOffset += .3f )
            {
                for( float radius = 3; radius < 8; radius += .6f )
                {
                    for( float angle = 0; angle < MathFunctions.PI * 2; angle += MathFunctions.PI / 32 )
                    {
                        Vec3 pos = center + new Vec3( MathFunctions.Cos( angle ),
                            MathFunctions.Sin( angle ), 0 ) * radius + new Vec3( 0, 0, zOffset );

                        Bounds volume = new Bounds( pos );
                        volume.Expand( volumeSize * .5f );

                        Body[] bodies = PhysicsWorld.Instance.VolumeCast(
                            volume, (int)ContactGroup.CastOnlyContact );

                        if( bodies.Length == 0 )
                            return pos;
                    }
                }
            }
        }