function createOrbit(%trans,%time) {
%dep = new staticShape() {
		datablock = LSB;	
	};
%dep.isCubic = true;
%dep.time = %time;
%dep.setDynamicTransform(%trans,0);
orbit(%dep);
return %dep;
}

function Orbit(%obj,%inside) {
echo(isObject(%obj.sch) SPC !%inside);
if (isObject(%obj.sch) && !%inside) {

	Cancel(%obj.sch);
	%obj.sch.delete();	
	%pos = getWords(%obj.lastDynTrans,0,2);
        %rot = getWords(%obj.lastDynTrans,3,6);
	%obj.setDynamicTransform(%pos SPC %rot,0);
        %obj.lastDynTrans = %pos SPC %rot;
	return;
}
	
%rot = getWords(%obj.lastDynTrans,3,6);
if (%obj.time < 0)
	%rot = rotadd(%rot,"0 0 1" SPC -1.57);
else
	%rot = rotadd(%rot,"0 0 1" SPC 1.57);
%pos = getWords(%obj.lastDynTrans,0,2);
%obj.setDynamicTransform(%pos SPC %rot,mabs(%obj.time/4));
%obj.lastDynTrans = %pos SPC %rot;
%obj.sch = schedule(mabs(%obj.time)/4*1000,%obj,"orbit",%Obj,1);
}

function River(%trans,%time,%radius,%count) {
%obj = createOrbit(%trans,%time);
%obj.radius = %radius;
schedule(%time/%count*1000,%obj,"addRiver",%obj,%time/%count*1000,%count--);
}

function addRiver(%obj,%time,%count) {
%dep = new staticShape() {
		datablock = LSB;	
	};
%dep.isCubic = true;
%pos = %obj.findEdge(VectorAdd(%obj.getPosition(),%obj.radius SPC "0 0"));
%dep.setDynamicTransform(%pos SPC invRot(%obj.getRotation()),%time/1000);
%obj.MountObject(%dep,0);
if (%count > 0) 
    schedule(%time,%obj,"addRiver",%obj,%time,%count--);
}

