Advertisement
sumguytwitches

Untitled

Sep 11th, 2020 (edited)
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. list engines in engs.
  2. set servos to ship:modulesnamed("ModuleRoboticRotationServo"). for s in servos s:setfield("traverse rate", 10).
  3.  
  4.  
  5.  
  6. function tilt { parameter tlt is 0. for s in servos s:setfield("target angle", tlt). }
  7. function vertThrust {
  8. set vth to 0.
  9. for e in engs if e:ignition set vth to vth + vdot(up:vector, e:facing:vector) * e:availablethrust.
  10. return max(1,vth).
  11. }
  12.  
  13.  
  14. function norm {
  15. parameter p0 is v(0,0,0).
  16. set u to (p0-body:position):normalized.
  17. set p1 to vxcl(u,facing:vector):normalized * 10.
  18. set p2 to body:geopositionof(angleaxis(120, u) * p1 + p0):position.
  19. set p3 to body:geopositionof(angleaxis(-120, u) * p1 + p0):position.
  20. set p1 to body:geopositionof(p1 + p0):position.
  21. return vcrs(p1-p2,p1-p3):normalized.
  22. }
  23.  
  24. lock curFwdTilt to vang(up:vector, vxcl(vcrs(up:vector, facing:vector),facing:vector)) * (choose 1 if vdot(vxcl(up:vector,facing:vector), facing:topvector) >= 1 else -1). //assumes forwards control point, spaceplane style.
  25.  
  26. when true then {
  27. tilt(-curFwdTilt + vang(up:vector, -velocity:surface)). //point engines retrograde, compensating for whatever our steering is currently tilted to. Assumes the forward direction of the craft (using yaw control and keeping roll close to 0) is pointing in the direction of travel.
  28. return ship:status <> "landed".
  29. }
  30.  
  31. set vesHeight to 1.3. //vessel height offset, larget for bigger crafts.
  32. lock altR to max(0,min(alt:radar, altitude - max(body:geopositionof(velocity:surface * 4):terrainheight,body:geopositionof(velocity:surface * 12):terrainheight))). //a little bit of very crude terrain sampling ahead
  33. set grav to body:mu/(body:radius^2).
  34. lock acc to max(1,(max(0.3,vdot(up:vector,facing:vector)) * vertThrust() * 0.9) / mass - grav).
  35. lock steering to vxcl(norm(velocity:surface * 1),velocity:surface).
  36.  
  37. lock throttle to grav/(vertThrust()/mass) + (-verticalspeed - max(0.5,min((alt:radar - vesHeight) ,5))) - sqrt(2 * acc * max(altR - 15 + verticalspeed * 0.1,0.0001)).
  38. when verticalspeed > 0 or ship:status <> "landed" then { lock throttle to 0. lock steering to lookdirup(norm(),facing:topvector). }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement