Advertisement
sumguytwitches

node functions

Feb 8th, 2021 (edited)
1,295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. lock rt to time:seconds + nextnode:eta + nextnode:orbit:period.
  2. lock dist to (positionat(ship, rt) - positionat(target, rt)):mag.
  3. function closest {
  4. parameter sgt is time:seconds.
  5. parameter sgstep to 1.
  6. set sgmindist to 9e9.
  7. lock sgdist to (positionat(ship, sgt) - positionat(target, sgt)):mag.
  8. until sgt - time:seconds > orbit:period {
  9. if sgdist < sgmindist {
  10. set sgmindist to sgdist.
  11. set sgmint to sgt.
  12. }
  13. set sgt to sgt + sgstep.
  14. }
  15. print sgmint. print sgmindist.
  16. return sgmint.
  17. }
  18.  
  19. function increment {
  20. parameter step.
  21. parameter type is "e".
  22.  
  23. if type = "e" set nextnode:eta to nextnode:eta + step.
  24. if type = "p" set nextnode:prograde to nextnode:prograde + step.
  25. if type = "n" set nextnode:normal to nextnode:normal + step.
  26. if type = "ro" set nextnode:radialout to nextnode:radialout + step.
  27. }
  28.  
  29. function adjust {
  30. parameter type is "e".
  31. set lastdist to dist.
  32. until lastdist < dist {
  33. set lastdist to dist. increment(step, type). wait 0. print dist.
  34. }.
  35. }
  36.  
  37. function tweak {
  38. parameter type is "e".
  39. adjust(type).
  40. set step to -step/2.
  41. adjust(type).
  42. increment(-step, type).
  43. print dist.
  44. }
  45.  
  46. set step to 1.
  47.  
  48. Lock sf to 1.
  49. Function nodeset {
  50. parameter n.
  51. parameter q.
  52.  
  53. set n:radialout to q:x.
  54. set n:normal to q:y.
  55. set n:prograde to q:z. wait 0.
  56. }
  57. function nodeget {
  58. parameter n.
  59. return v(n:radialout,n:normal, n:prograde).
  60. }
  61.  
  62. function nodedelta {
  63. parameter n.
  64. parameter d.
  65. nodeset(n,nodeget(n)+d).
  66. }
  67.  
  68. function grad {
  69. parameter n.
  70. parameter d is 0.001.
  71. local y0 is sf.
  72. local v0 is nodeget(n).
  73.  
  74. function t {
  75. parameter q.
  76. nodedelta(n,d*q).
  77. local y is (sf-y0)/d.
  78. return y.
  79. }
  80.  
  81. local x is t(v(1,0,0)).
  82. local y is t(v(-1,1,0)).
  83. local z is t(v(0,-1,1)).
  84. nodeset(n,v0).
  85. return v(x,y,z).
  86. }.
  87. function matchVelAtNode2 {
  88. parameter nodeX is nextnode.
  89. parameter tarvel is "none".
  90.  
  91. set tx to nodeX:time.
  92.  
  93. set nodeX:prograde to 0.
  94. set nodeX:radialout to 0.
  95. set nodeX:normal to 0.
  96.  
  97. wait 0.1.
  98.  
  99. set nodepro to velocityat(ship, tx):orbit:normalized.
  100. set noderad to vxcl(nodepro, (positionat(ship, tx) - body:position)):normalized.
  101. set nodenorm to vcrs(nodepro, noderad):normalized.
  102.  
  103. set tarvel to choose tarvel - velocityat(ship, tx):orbit if tarvel:istype("vector") else velocityat(target, tx):orbit - velocityat(ship, tx):orbit.
  104.  
  105. set pro to vdot(nodepro, tarvel).
  106. set rad to vdot(noderad, tarvel).
  107. set norm to vdot(nodenorm, tarvel).
  108.  
  109. set nodeX:prograde to pro.
  110. set nodeX:radialout to rad.
  111. set nodeX:normal to norm.
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement