Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //brief node_escape.ks: Creates a node which escapes the current parent SOI either prograde or retrograde wise.
- //
- //Warning: Assumes the current orbit is somewhat circular. Assumes you have somewhat the same inclination as the current parent
- //Script Parameters:
- // par_direction, type string. Either prograde or retrograde. The direction you want to escape to
- // par_velocity, type scalar (m/s). The requested escape-velocity. if 0, we will calculate a "just enough" speed
- // par_phase, type scalar (deg). The angle you want to burn earlier/later.
- parameter par_direction is "prograde".
- parameter par_velocity is 0.
- parameter par_phase is -45.
- //Can't get the velocity of the current body directly, as its zero. But we can get the body:body and inverse it
- //If we want to escape retrograde, we must take the current body:body prograde and visa versa
- if (par_direction = "retrograde") {
- set vec_escape to ship:body:body:prograde:vector:normalized.
- } else {
- if not (par_direction = "prograde") {
- //Can't quit scripts? So just return to default + warning.
- print "Warning: par_direction requires either 'prograde' or 'retrograde'. Assuming prograde. Invalid arg: " + par_direction.
- }
- set vec_escape to ship:body:body:retrograde:vector:normalized.
- }
- //Get current velocity and the cross product between the escape-vector and vec_velocity.
- set vec_vel to ship:prograde:vector:normalized.
- set vec_cross to VCRS(vec_escape, vec_vel):normalized.
- //Get the angle between the two velocity vectors
- set phase_deg to vectorangle(vec_escape, vec_vel).
- //When the cross product flips the other way, we just missed the manouver node
- //Note that when traveling clockwise (orbit-wise) the cross-product is already upside down
- if (orbit:inclination<90 and vec_cross:y < 0) or (orbit:inclination>90 and vec_cross:y > 0) {
- set phase_deg to 360-phase_deg.
- }
- //We are inside the current body SOI for a while, so put the phase a bit earlier (WIP)
- //Seems to be related to the degrees the current parent moves around the parent:parent (in the escape time) + the amount of degrees you complete before escaping. So with a higher par_velocity, you need a lower par_phase and visa versa
- set phase_deg to phase_deg + par_phase.
- if (phase_deg < 0) {
- set phase_deg to phase_deg+360.
- }
- //Get eta in sec and print some info
- set eta_sec to (ship:orbit:period/360) * phase_deg.
- print "Phase: " + phase_deg.
- print "ETA : " + eta_sec.
- //If zero, calculate our own (seems a tad inaccurate)
- if(par_velocity = 0) {
- set new_periapsis to (ship:apoapsis+ship:periapsis)/2.
- set margin to 50 * 1000.
- set new_semimajor to (new_periapsis+ship:body:radius + ship:body:soiradius+ship:body:radius + margin) / 2.
- set eta_curVel to velocityat(ship, time+eta_sec):orbit:mag.
- set eta_reqVel to SQRT(ship:body:mu * (2/(new_periapsis+ship:body:radius) - 1/new_semimajor)).
- set par_velocity to eta_reqVel - eta_curVel.
- print "Calculated escape vel: " + par_velocity.
- }
- //Create node
- set man_node to node((time+eta_sec):seconds, 0, 0, par_velocity).
- add man_node.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement