Skip to content

Instantly share code, notes, and snippets.

@SYZYGY-DEV333
Created July 17, 2020 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SYZYGY-DEV333/4e5c2a03c4a809dd2aff465ba6f8d6bc to your computer and use it in GitHub Desktop.
Save SYZYGY-DEV333/4e5c2a03c4a809dd2aff465ba6f8d6bc to your computer and use it in GitHub Desktop.
A hover script for KSP using RedOnion
window=new(ui.Window,"Hover Dialog",ui.Layout.Vertical)
window.ChildAnchors=ui.Anchors.Fill
hovering = false
target_alt = 0
target_vs = 0
old_throttle = ship.throttle
window.Add(new(ui.Button,"Start Hover",function()
print("Start Hover")
hovering = true
end))
window.Add(new(ui.Button,"Stop Hover",function()
print("Stop Hover")
hovering = false
ship.throttle = old_throttle
autopilot.disable()
end))
window.Add(new(ui.Label,"Altitude:"))
txtbox = window.Add(new(ui.TextBox,"0"))
window.Add(new(ui.Button,"Update Altitude",function()
print("Target Altitude: "..txtbox.Text)
target_alt = tonumber(txtbox.Text)
end))
window.Add(new(ui.Button,"Higher",function()
txtbox.Text = tostring(tonumber(txtbox.Text) + 2)
target_alt = tonumber(txtbox.Text)
print("Target Altitude: "..txtbox.Text)
end))
window.Add(new(ui.Button,"Lower",function()
txtbox.Text = tostring(tonumber(txtbox.Text) - 2)
target_alt = tonumber(txtbox.Text)
print("Target Altitude: "..txtbox.Text)
end))
while ( true )
do
if ( hovering == true ) then
if (ship.altitude < (target_alt - 2) ) then
target_vs = 5
if ( ship.native.verticalSpeed < target_vs ) then
ship.throttle = 1
else
ship.throttle = 0
end
elseif ( ship.altitude > (target_alt + 2) ) then
target_vs = -5
if ( ship.native.verticalSpeed < target_vs ) then
ship.throttle = 1
else
ship.throttle = 0
end
else
target_vs = 0
if ( ship.native.verticalSpeed < target_vs ) then
ship.throttle = 1
else
ship.throttle = 0
end
end
end
sleep(0.1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment