View difference between Paste ID: j6rWiAND and xSjerGzW
SHOW: | | - or go back to the newest paste.
1-
set station to vessel("Space Race").
1+
2
	parameter p is core:part.
3
	set pp to p:parent.
4
	if pp:typename = "dockingport" set port to pp.
5
	else findPort(pp).
6
}
7
findPort().
8-
	set g to station:partstagged(str)[0].
8+
9
core:part:controlfrom().
10
port:undock().
11
wait 0.2.
12
kuniverse:forceactive(ship).
13-
set gate to ship:rootpart.
13+
wait 0.2.
14
list engines in engs. for e in engs e:activate.
15-
set rel_v to velocity:orbit - station:velocity:orbit.
15+
sas off.
16
set t to time:seconds.
17
wait 1.
18
set target to "Space Race".
19
lock rel_v to choose (velocity:orbit - target:velocity:orbit) if hastarget else v(0,0,0).
20
set gateFA to v(1,0,0).
21
set gateVel to v(0,0,0).
22-
set th to 0. set st to facing:vector.
22+
23
when vessel("space race"):partsdubbedpattern("station")[0]:tag = "stationGo" then set basespeed to 8 + random()*1.
24
set docking to false.
25
for eng in ship:partsdubbedpattern("vernier") {
26
	set eng:deadband to 0.005.
27-
	if pp:typename = "dockingport" {
27+
28-
		set port to pp.
28+
29-
	} else {
29+
30-
		findPort(pp).
30+
31
set col0 to rgba(0,0,0,0).
32
for i in range(8) {
33
	set i2 to i + 1.
34
	set str to racecourse[i2].
35-
//function undockAndGo {
35+
	set g to target:partstagged(str)[0].
36-
	set docking to false.
36+
37-
	core:part:controlfrom().
37+
38-
	port:undock().
38+
39-
    set station to vessel("Space Race").
39+
40-
	wait 0.2.
40+
41-
	kuniverse:forceactive(ship).
41+
42-
	wait 0.2.
42+
43-
	port:getmodule("moduledockingnode"):setfield("docking acquire force", 0).
43+
44-
	sas off.
44+
	for d in target:dockingports {
45-
	set t to time:seconds.
45+
46-
	wait 1.
46+
47-
	set target to "Space Race".
47+
48
			set docking to true.
49-
//}
49+
50-
//undockAndGo().
50+
51
	if docking when (gate:nodeposition-port:nodeposition):mag < 0.5 then { exit2(). }
52
	
53-
	list engines in engs.
53+
54-
	for en in engs {
54+
55-
		 en:activate().
55+
	lock throttle to 0. rcs off. unlock throttle. set ship:control:neutralize to true. unlock steering.
56
}
57-
	for eng in ship:partsdubbedpattern("vernier") {
57+
58-
		set eng:deadband to 0.005.
58+
59
	if i = 1 {
60
		if defined tOld set tNew to time:seconds - tOld.
61
		set tOld to time:seconds.
62
63
		if defined tNew print "<color>Round time: " + round(tNew,2) + "s</color>". 
64
	}
65
	
66
    set gate to gates[i][0].
67
	set hl:color to col0.
68
	set hl to gates[i][1]. 
69
70
    set i to i + 1.
71
    if i = 8 set i to 0.
72
    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 {
73
        print "passed gate " + gate:tag.
74
        next().
75
    }
76
	set gateVel to rel_v.
77-
    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 {
77+
78-
		print "passed gate " + gate:tag.
78+
79
	set l to gate:children[0]:getmodule("moduleColoredLensLight").
80
	
81
	set hl:color to rgba(l:getfield("light r"),l:getfield("light g"),l:getfield("light b"),0.3).
82-
	print "next(): gatevel " + gateVel.
82+
83
next().
84
85
rcs on.
86
set steeringmanager:maxstoppingtime to 2.
87
set steeringmanager:pitchpid:kp to 2.
88
set steeringmanager:yawpid:kp to 2.
89-
	print "next() done".
89+
90
set steeringmanager:yawpid:kd to 0.3.
91
set tpid to pidloop(0.5,0,0.0,-1,1).
92
set spid to pidloop(tpid:kp,tpid:ki,tpid:kd,-1,1).
93
set fpid to pidloop(tpid:kp,tpid:ki,tpid:kd,-1,1).
94
95
set th to 0. set st to facing.
96-
when not(ship:messages:empty) then {
96+
97-
	set msg to ship:messages:pop:content.
97+
98-
	print "msg: " + msg.
98+
99-
	if msg[0] = "go" {
99+
100-
		set basespeed to msg[1].
100+
101
when true then {
102
	set gateFA to gate:facing:vector.
103
	set side to vxcl(gateFA, gate:position):mag.
104-
function go {
104+
105-
	parameter spd is 8.
105+
		set fwdDist to vdot(gateFA, port:nodeposition - gate:nodeposition).
106-
	set basespeed to spd.
106+
		set wantPos to gate:position + gateFA *  (min(3, max(fwdDist - 1, -0.1 + 8*side)) + min(15, side / 2)).
107
		set wanted_v to gateVel * gateT + (1-gateT) * (wantPos:normalized * (wantPos:mag^0.75)).
108
		set ve to wanted_v - rel_v.
109-
	set ship:control:neutralize to true. wait 0. lock throttle to 0. rcs off. unlock throttle. wait 0. unlock steering.
109+
110
		set st to choose -gateFA if side < 1 and gate:position:mag < 10 else (ve + (rel_v:normalized * (-5/20))).
111
	}
112
	else {
113-
	for d in station:dockingports {
113+
		if vdot(gate:position, gate:facing:vector) < 0 set gateFA to -gateFA.
114
		set sl to baseSpeed + max(0.001,side-5)^0.1.
115
		set wanted_v to gateVel * gateT + (1-gateT) * ((gate:position + gateFA * max(-12, 5 - side^1.25)):normalized * sl).
116
		set ve to wanted_v - rel_v.
117
		set st to ve + (rel_v:normalized * (-baseSpeed/20)).
118
	}
119
120
	set gateT to max(0,gateT-0.01).
121-
		port:getmodule("moduledockingnode"):setfield("docking acquire force", 150).
121+
    if vang(facing:vector, ve) < 60
122-
		when (gate:nodeposition-port:nodeposition):mag < 0.5 then { exit2(). }
122+
        set th to vdot(facing:vector,ve) * 3.
123-
		on ship:parts:length {
123+
    else set th to 0.
124-
			set TRANSFERALL("OXIDIZER", ship:elements[0], core:element):active to true.
124+
125-
			set TRANSFERALL("LIQUIDFUEL", ship:elements[0], core:element):active to true.
125+
	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))).
126
    return rcs.
127-
	} 
127+
128
129
130
131
//set camDist to 5.
132
set trackcam to false. 
133
//set cam to addons:camera:flightcamera.
134
//set gPos to -facing:vector * 80.
135
//set camMode to "station".
136
when trackcam then {
137
	set gPos to gPos * 0.97 + (rel_v:normalized * 5 + gate:position):normalized * 0.03.
138
139
	if camMode = "gate" set cam:position to gPos:normalized * -camDist.
140
	else if camMode = "puke" set cam:position to facing:vector * -camDist.
141
	else if camMode = "chase" set cam:position to rel_v:normalized * -camDist. 
142
	else if hastarget set cam:position to target:position:normalized * -camDist + vxcl(target:position,gPos:normalized * -camDist/2).
143
	return true.
144-
set vd_ve to vecdraw(v(0,0,0), v(0,0,0), yellow, "", 1, true, 0.4).
144+
145
146-
print "starting trigger". wait 1.
146+

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×