Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lock rt to time:seconds + nextnode:eta + nextnode:orbit:period.
- lock dist to (positionat(ship, rt) - positionat(target, rt)):mag.
- function closest {
- parameter sgt is time:seconds.
- parameter sgstep to 1.
- set sgmindist to 9e9.
- lock sgdist to (positionat(ship, sgt) - positionat(target, sgt)):mag.
- until sgt - time:seconds > orbit:period {
- if sgdist < sgmindist {
- set sgmindist to sgdist.
- set sgmint to sgt.
- }
- set sgt to sgt + sgstep.
- }
- print sgmint. print sgmindist.
- return sgmint.
- }
- function increment {
- parameter step.
- parameter type is "e".
- if type = "e" set nextnode:eta to nextnode:eta + step.
- if type = "p" set nextnode:prograde to nextnode:prograde + step.
- if type = "n" set nextnode:normal to nextnode:normal + step.
- if type = "ro" set nextnode:radialout to nextnode:radialout + step.
- }
- function adjust {
- parameter type is "e".
- set lastdist to dist.
- until lastdist < dist {
- set lastdist to dist. increment(step, type). wait 0. print dist.
- }.
- }
- function tweak {
- parameter type is "e".
- adjust(type).
- set step to -step/2.
- adjust(type).
- increment(-step, type).
- print dist.
- }
- set step to 1.
- Lock sf to 1.
- Function nodeset {
- parameter n.
- parameter q.
- set n:radialout to q:x.
- set n:normal to q:y.
- set n:prograde to q:z. wait 0.
- }
- function nodeget {
- parameter n.
- return v(n:radialout,n:normal, n:prograde).
- }
- function nodedelta {
- parameter n.
- parameter d.
- nodeset(n,nodeget(n)+d).
- }
- function grad {
- parameter n.
- parameter d is 0.001.
- local y0 is sf.
- local v0 is nodeget(n).
- function t {
- parameter q.
- nodedelta(n,d*q).
- local y is (sf-y0)/d.
- return y.
- }
- local x is t(v(1,0,0)).
- local y is t(v(-1,1,0)).
- local z is t(v(0,-1,1)).
- nodeset(n,v0).
- return v(x,y,z).
- }.
- function matchVelAtNode2 {
- parameter nodeX is nextnode.
- parameter tarvel is "none".
- set tx to nodeX:time.
- set nodeX:prograde to 0.
- set nodeX:radialout to 0.
- set nodeX:normal to 0.
- wait 0.1.
- set nodepro to velocityat(ship, tx):orbit:normalized.
- set noderad to vxcl(nodepro, (positionat(ship, tx) - body:position)):normalized.
- set nodenorm to vcrs(nodepro, noderad):normalized.
- set tarvel to choose tarvel - velocityat(ship, tx):orbit if tarvel:istype("vector") else velocityat(target, tx):orbit - velocityat(ship, tx):orbit.
- set pro to vdot(nodepro, tarvel).
- set rad to vdot(noderad, tarvel).
- set norm to vdot(nodenorm, tarvel).
- set nodeX:prograde to pro.
- set nodeX:radialout to rad.
- set nodeX:normal to norm.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement