local function rockspeed ()
local lastspeed = 0
while (true) do
local sx,sy,sz = Spring.GetUnitVelocity (unitID)
if (sx and sy and sz) then
local speed = (math.abs (sx)+ math.abs (sy) + math.abs (sz))*10
local speeddiff = speed - lastspeed
if (speeddiff < -3) then
Spring.Echo ("unit " .. unitID .. " slowing down " .. speeddiff)
Turn (body, x_axis, math.rad(20), math.rad(180))
WaitForTurn (body, x_axis)
else if (speeddiff > 3) then
Turn (body, x_axis, math.rad(-20),math.rad(180))
WaitForTurn (body, x_axis)
Spring.Echo ("unit " .. unitID .. " going faster" .. speeddiff)
else
Turn (body, x_axis, 0,math.rad(360))
WaitForTurn (body, x_axis)
end
end
lastspeed=speed
end
Sleep (100)
end
end