Advertisement
sumguytwitches

0zin docking

Aug 26th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. set localport to ship:controlpart.
  2. set sep to 50.
  3. set sl to 0.
  4. lock offset to v(0,0,0).
  5. if target:istype("Vessel") set tVes to target.
  6. else set tVes to target:ship.
  7. set fpid to pidloop(3,0.01,0.1,-1,1).
  8. set tpid to pidloop(fpid:kp,fpid:ki,fpid:kd,-1,1).
  9. set spid to pidloop(fpid:kp,fpid:ki,fpid:kd,-1,1).
  10.  
  11. function rv {
  12. set rel_v to velocity:orbit - tVes:velocity:orbit.
  13. if target:istype("Vessel") set fa to target:facing.
  14. else set fa to target:portfacing.
  15. set wv_pos to (target:position + offset + fa:vector * sep) - localport:position.
  16. set wanted_v to wv_pos:normalized * min(sl , (wv_pos:mag * 0.25)^0.5).
  17. set ve to wanted_v - rel_v.
  18. }
  19.  
  20. set dock to true.
  21. when true then {
  22. rv().
  23. set ship:control:translation to v(-spid:update(time:seconds, vdot(facing:starvector,ve)),-tpid:update(time:seconds,vdot(facing:topvector,ve)),-fpid:update(time:seconds,vdot(facing:vector,ve))).
  24. return dock.
  25. }
  26. lock steering to lookdirup(-target:facing:vector, target:facing:topvector).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement