Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findPort {
- parameter p is core:part.
- set pp to p:parent.
- if pp:typename = "dockingport" set port to pp.
- else findPort(pp).
- }
- findPort().
- core:part:controlfrom().
- port:undock().
- wait 0.2.
- kuniverse:forceactive(ship).
- wait 0.2.
- list engines in engs. for e in engs e:activate.
- sas off.
- set t to time:seconds.
- wait 1.
- set target to "Space Race".
- lock rel_v to choose (velocity:orbit - target:velocity:orbit) if hastarget else v(0,0,0).
- set gateFA to v(1,0,0).
- set gateVel to v(0,0,0).
- set baseSpeed to 0.
- when vessel("space race"):partsdubbedpattern("station")[0]:tag = "stationGo" then set basespeed to 8 + random()*1.
- set docking to false.
- for eng in ship:partsdubbedpattern("vernier") {
- set eng:deadband to 0.005.
- }
- set racecourse to list("PStart","w1","w2","w3","w4","w5","w6","w7","w8","PEnd").
- set gates to list().
- set col0 to rgba(0,0,0,0).
- for i in range(8) {
- set i2 to i + 1.
- set str to racecourse[i2].
- set g to target:partstagged(str)[0].
- gates:add(list(g, highlight(g, col0) )).
- }
- set hl to gates[0][1].
- set i to 0.
- set gateT to 0.
- function dock {
- set minAng to 180.
- for d in target:dockingports {
- if d:nodetype = port:nodetype and d:state = "ready" and vang(-d:portfacing:vector,d:position) < minAng {
- set gate to d.
- set minAng to vang(-d:portfacing:vector,d:position).
- set docking to true.
- }
- }
- if docking when (gate:nodeposition-port:nodeposition):mag < 0.5 then { exit2(). }
- }
- function exit2 {
- lock throttle to 0. rcs off. unlock throttle. set ship:control:neutralize to true. unlock steering.
- }
- function next {
- if i = 1 {
- if defined tOld set tNew to time:seconds - tOld.
- set tOld to time:seconds.
- if defined tNew print "<color>Round time: " + round(tNew,2) + "s</color>".
- }
- set gate to gates[i][0].
- set hl:color to col0.
- set hl to gates[i][1].
- set i to i + 1.
- if i = 8 set i to 0.
- when abs(vdot(gateFA, gate:position)) < rel_v:mag/20 and vdot(rel_v:normalized, gate:position) < 0 and vxcl(gateFA,gate:position):mag < 2.6 then {
- print "passed gate " + gate:tag.
- next().
- }
- set gateVel to rel_v.
- set gateT to 1.
- set l to gate:children[0]:getmodule("moduleColoredLensLight").
- set hl:color to rgba(l:getfield("light r"),l:getfield("light g"),l:getfield("light b"),0.3).
- }
- next().
- rcs on.
- set steeringmanager:maxstoppingtime to 2.
- set steeringmanager:pitchpid:kp to 2.
- set steeringmanager:yawpid:kp to 2.
- set steeringmanager:pitchpid:kd to 0.3.
- set steeringmanager:yawpid:kd to 0.3.
- set tpid to pidloop(0.5,0,0.0,-1,1).
- set spid to pidloop(tpid:kp,tpid:ki,tpid:kd,-1,1).
- set fpid to pidloop(tpid:kp,tpid:ki,tpid:kd,-1,1).
- set th to 0. set st to facing.
- lock throttle to th.
- lock steering to st.
- when true then {
- set gateFA to gate:facing:vector.
- set side to vxcl(gateFA, gate:position):mag.
- if docking {
- set fwdDist to vdot(gateFA, port:nodeposition - gate:nodeposition).
- set wantPos to gate:position + gateFA * (min(3, max(fwdDist - 1, -0.1 + 8*side)) + min(15, side / 2)).
- set wanted_v to gateVel * gateT + (1-gateT) * (wantPos:normalized * (wantPos:mag^0.75)).
- set ve to wanted_v - rel_v.
- set st to choose -gateFA if side < 1 and gate:position:mag < 10 else (ve + (rel_v:normalized * (-5/20))).
- }
- else {
- if vdot(gate:position, gate:facing:vector) < 0 set gateFA to -gateFA.
- set sl to baseSpeed + max(0.001,side-5)^0.1.
- set wanted_v to gateVel * gateT + (1-gateT) * ((gate:position + gateFA * max(-12, 5 - side^1.25)):normalized * sl).
- set ve to wanted_v - rel_v.
- set st to ve + (rel_v:normalized * (-baseSpeed/20)).
- }
- set gateT to max(0,gateT-0.01).
- if vang(facing:vector, ve) < 60
- set th to vdot(facing:vector,ve) * 3.
- else set th to 0.
- 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))).
- return rcs.
- }
- //set camDist to 5.
- set trackcam to false.
- //set cam to addons:camera:flightcamera.
- //set gPos to -facing:vector * 80.
- //set camMode to "station".
- when trackcam then {
- set gPos to gPos * 0.97 + (rel_v:normalized * 5 + gate:position):normalized * 0.03.
- if camMode = "gate" set cam:position to gPos:normalized * -camDist.
- else if camMode = "puke" set cam:position to facing:vector * -camDist.
- else if camMode = "chase" set cam:position to rel_v:normalized * -camDist.
- else if hastarget set cam:position to target:position:normalized * -camDist + vxcl(target:position,gPos:normalized * -camDist/2).
- return true.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement