Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------------------------------------------------------
- -------------------------------------------------------------------------------
- --
- -- OrbitBot, a simple robot that finds the nearest TestItem and orbits it
- -- Note that this relies on line-of-sight navigation, so only good for open levels
- --
- -------------------------------------------------------------------------------
- -------------------------------------------------------------------------------
- -------------------------------------------------------------------------------
- -------------------------------------------------------------------------------
- -------------------------------------------------------------------------------
- -- Setup; all vars declared here are global unless declared with "local" keyword
- function main()
- orbitAng = 0
- orbitRadius = 900
- isInOrbit = false
- targetItem = nil
- end
- -------------------------------------------------------------------------------
- -- This function is called once and should return the robot's name
- function getName()
- return( "OrbitBot" )
- end
- -------------------------------------------------------------------------------
- -- This is called by the robot's idle routine each tick.
- -- This function must be present for the robot to work!
- items = { }
- function onTick(deltaTime)
- -- if(targetItem == nil) then
- -- table.clear(items)
- -- targetItem = findClosest(findGlobalObjects(items, ObjType.SoccerBallItem))
- --end
- local targetItems = findGlobalObjects(items, ObjType.SoccerBallItem);
- -- table.insert(targetItems,0,bot:getShip());
- local count = 0;
- for key, targetItem in pairs(targetItems) do
- local cent = point.new(0,0);
- local pos = targetItem:getLoc();
- local delt = pos-cent;
- local deltdir = point.normalize(delt);
- local ang = point.angleTo(cent, pos);
- local nang = ang+(math.pi/2);
- local ndir = point.new(math.cos(nang), math.sin(nang));
- local force = -2000;
- local nvel = ndir * -1000 + deltdir*force;
- local cvel = targetItem:getVel();
- local p = 0.05;--TODO use a time delta for this later
- local lerped = (((nvel-cvel)*p)+cvel);
- local dst = point.length(delt)
- if (dst < 470) then
- if (dst > 280) then
- targetItem:setLoc(deltdir*270);
- elseif (dst < 150) then
- targetItem:setLoc(deltdir*5000);
- end
- end
- --targetItem:setLoc(point.new(100,100));
- targetItem:setVel(lerped);
- end
- -- bot:setThrustToPt( dest ) -- Travel towards calculated point
- --bot:setAngle( point.angleTo( botLoc, itemLoc ) ) -- Aim ship that way too
- end
Advertisement
Add Comment
Please, Sign In to add comment