Created
March 12, 2015 00:41
-
-
Save shoffing/a42c812d3133cf73ffcb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local turnLeft = false | |
function Update() | |
-- Store our angular velocity in a variable to make it easier to use | |
local angVel = gyro:AngVel() | |
if ranger:Range() > 0 then | |
-- We see another ship, stop spinning, start ramming, | |
-- and remember which way to turn if we lose it again | |
-- Use the standard thrusters to cancel out our angular velocity | |
thrustFL:SetThrust(-angVel) | |
thrustFR:SetThrust(angVel) | |
thrustBL:SetThrust(angVel) | |
thrustBR:SetThrust(-angVel) | |
-- Ignite the ramming thruster | |
ramThrust:Ignite() | |
-- Figure out which way to turn if we lose the ship again | |
if angVel > 0 then | |
-- We were spinning left when we saw this target, | |
-- so we should turn right if we lose it. | |
turnLeft = false | |
else | |
-- We were spinning right when we saw this target, | |
-- so we should turn left if we lose it. | |
turnLeft = true | |
end | |
else | |
-- We don't see another ship, spin around to find one | |
-- Figure out which way to turn | |
local desiredAngVel = turnLeft and 45 or -45 | |
-- Use the standard thrusters to spin the ship at the desired angular speed. | |
thrustFL:SetThrust(desiredAngVel - angVel) | |
thrustFR:SetThrust(angVel - desiredAngVel) | |
thrustBL:SetThrust(angVel - desiredAngVel) | |
thrustBR:SetThrust(desiredAngVel - angVel) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment