|
@@ -0,0 +1,313 @@
|
|
1
|
+#zskcam
|
|
2
|
+import bge
|
|
3
|
+import mathutils
|
|
4
|
+from mathutils import *
|
|
5
|
+scene = bge.logic.getCurrentScene()
|
|
6
|
+cont = bge.logic.getCurrentController()
|
|
7
|
+own = cont.owner
|
|
8
|
+def main():
|
|
9
|
+ dict = bge.logic.globalDict
|
|
10
|
+ camempty = scene.objects['camEmpty.001']
|
|
11
|
+ controlcube = scene.objects['control_cube.002']
|
|
12
|
+
|
|
13
|
+ camCube = scene.objects['camCube']
|
|
14
|
+
|
|
15
|
+ dropinCol = controlcube.sensors['dropinCol']
|
|
16
|
+ LAST_GRIND = controlcube['LAST_GRIND']
|
|
17
|
+ up = cont.sensors['up']
|
|
18
|
+ ray = cont.sensors['up']
|
|
19
|
+ down = cont.sensors['down']
|
|
20
|
+ left = cont.sensors['left']
|
|
21
|
+ right = cont.sensors['right']
|
|
22
|
+ distance = 0.12
|
|
23
|
+ cam = cont.actuators["Camera"]
|
|
24
|
+ near = cont.sensors["Near"]
|
|
25
|
+ move = own.actuators["move"]
|
|
26
|
+ #match camera actuaotor
|
|
27
|
+ cam_def_height = dict['cam_height'] #-.1 #-.6
|
|
28
|
+ #cam_def_min = 1.6
|
|
29
|
+ #cam_def_max = 2.4
|
|
30
|
+ cam_def_min = dict['cam_min']
|
|
31
|
+ cam_def_max = dict['cam_max']
|
|
32
|
+ cam_height = cam.height
|
|
33
|
+ cam_min = cam.min
|
|
34
|
+ cam_max = cam.max
|
|
35
|
+ lasty = controlcube['lasty']
|
|
36
|
+ cam_moved = 0
|
|
37
|
+ lastCamheight = controlcube['lastCamheight']
|
|
38
|
+ raised = 0
|
|
39
|
+ walk = controlcube['walk']
|
|
40
|
+ cam.axis = 4
|
|
41
|
+ ccheight = controlcube.worldPosition[2]
|
|
42
|
+ camwpz = own.worldPosition[2]
|
|
43
|
+ zdist = camwpz - ccheight
|
|
44
|
+
|
|
45
|
+ cam1 = scene.objects['Camera.003']
|
|
46
|
+ cam2 = scene.objects['freecam']
|
|
47
|
+ cam3 = scene.objects['followcam']
|
|
48
|
+
|
|
49
|
+ camList = scene.cameras
|
|
50
|
+ freecam = camList["freecam"]
|
|
51
|
+
|
|
52
|
+ if 'init' not in own:
|
|
53
|
+ own['init'] = 1
|
|
54
|
+ own['last_move_x'] = 0
|
|
55
|
+ own['last_move_y'] = 0
|
|
56
|
+ own['last_move_z'] = 0
|
|
57
|
+ own['last_rot_x'] = 0
|
|
58
|
+ own['last_rot_y'] = 0
|
|
59
|
+ own['last_rot_z'] = 0
|
|
60
|
+ own['idlecampos_x'] = 0
|
|
61
|
+ own['speed_mult'] = 1.00
|
|
62
|
+ controlcube['driving'] = False
|
|
63
|
+ acam = scene.active_camera
|
|
64
|
+ focallength = dict['focal_length']
|
|
65
|
+ cam1.lens = focallength
|
|
66
|
+ cam2.lens = focallength
|
|
67
|
+ cam3.lens = focallength
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+ #if 1 == 1:
|
|
71
|
+ #if own['playback'] == False:
|
|
72
|
+ if controlcube['driving'] == False:
|
|
73
|
+ if down.triggered == True and LAST_GRIND == False and walk == 0:
|
|
74
|
+ hitPosition = down.hitPosition
|
|
75
|
+ distance = own.getDistanceTo(hitPosition)
|
|
76
|
+ cam_moved = 1
|
|
77
|
+ if distance < .2:
|
|
78
|
+ camempty['hitdown'] = True
|
|
79
|
+ cam.height = cam_height + .3
|
|
80
|
+ cam.damping = .0
|
|
81
|
+ #print("raise cam")
|
|
82
|
+ if zdist < -.2:
|
|
83
|
+ cam.height = lastCamheight + .01
|
|
84
|
+ cam.damping = .0
|
|
85
|
+ raised = 1
|
|
86
|
+ if (distance > .4 and distance < .6) and zdist > -.2 and raised == 0:
|
|
87
|
+ camheight2 = cam.height - .001
|
|
88
|
+ if cam.height < .2:
|
|
89
|
+ cam.height = camheight2
|
|
90
|
+ #print("slow lower")
|
|
91
|
+ if distance >= .6 and zdist > -.2 and raised == 0:
|
|
92
|
+ cam.height = cam.height - .02
|
|
93
|
+ #print("slow lower2")
|
|
94
|
+ if down.triggered == False and LAST_GRIND == False and cam_moved == 0 and walk == 0:
|
|
95
|
+ camempty['hitdown'] = False
|
|
96
|
+ if cam_height > (cam_def_height + .06) and zdist > -.2 and raised == 0:
|
|
97
|
+ cam.height = cam_height - .02
|
|
98
|
+ if cam_height < -.6 and cam_moved == 0 and LAST_GRIND == False and zdist > -.2 and raised == 0 and walk == 0:
|
|
99
|
+ cam_height = .1
|
|
100
|
+ if LAST_GRIND == True and walk == 0:
|
|
101
|
+ if cam.height < -.5 or zdist < -.2:
|
|
102
|
+ cam.height = cam.height + .013
|
|
103
|
+ if cam.height >= -.5 and not down.triggered:
|
|
104
|
+ pass
|
|
105
|
+
|
|
106
|
+ if walk == 1:
|
|
107
|
+ if dropinCol.positive == True and lasty == True:
|
|
108
|
+ pass
|
|
109
|
+ else:
|
|
110
|
+ pass
|
|
111
|
+ controlcube['lastCamheight'] = cam.height
|
|
112
|
+ #########
|
|
113
|
+ cam.min = dict['cam_min']
|
|
114
|
+ cam.max = dict['cam_max']
|
|
115
|
+ cont.activate(own.actuators['Camera'])
|
|
116
|
+ ########
|
|
117
|
+
|
|
118
|
+ if near.triggered == True and walk == 0:
|
|
119
|
+ #print("near")
|
|
120
|
+ if cam.min < 1:
|
|
121
|
+ cam.min = cam.min + .1
|
|
122
|
+ cam.max = cam.max + .1
|
|
123
|
+ cam.height = cam_height + .01
|
|
124
|
+ cam.damping = .001
|
|
125
|
+ cont.activate(move)
|
|
126
|
+
|
|
127
|
+ else:
|
|
128
|
+ #print("far")
|
|
129
|
+ cont.deactivate(move)
|
|
130
|
+ if cam.min > cam_def_min:
|
|
131
|
+ cam.min = cam.min - .05
|
|
132
|
+ cam.max = cam.max - .05
|
|
133
|
+ cam.damping = .0
|
|
134
|
+ if cam.damping != 0 and down.triggered == False and near.triggered == False:
|
|
135
|
+ cam.damping = 0.91
|
|
136
|
+
|
|
137
|
+ obj = cont.owner
|
|
138
|
+ cube = controlcube
|
|
139
|
+ to = cube
|
|
140
|
+ from2 = obj
|
|
141
|
+ distance = 0.0
|
|
142
|
+ property = ""
|
|
143
|
+ face = 1
|
|
144
|
+ xray = 0
|
|
145
|
+ poly = 0
|
|
146
|
+ hit = obj.rayCast( to, from2, distance, property, face, xray, poly)
|
|
147
|
+ control = "control_cube.002"
|
|
148
|
+ hitobj = hit[0]
|
|
149
|
+ hitobj = str(hitobj)
|
|
150
|
+ if hitobj != control and walk == 0:
|
|
151
|
+ cam.damping = .0
|
|
152
|
+ if cam.height < 3:
|
|
153
|
+ cam.height = cam_height + .1
|
|
154
|
+
|
|
155
|
+ if dict['menu_idle_timer'] > 300:
|
|
156
|
+ move_len = 2048
|
|
157
|
+ if own['idlecampos_x'] < move_len:
|
|
158
|
+ own['idlecampos_x'] += 1
|
|
159
|
+ if own['idlecampos_x'] == move_len:
|
|
160
|
+ own['idlecampos_x'] = 0
|
|
161
|
+
|
|
162
|
+ if own['idlecampos_x'] < (move_len / 2):
|
|
163
|
+ move = [.0001, 0, 0]
|
|
164
|
+ freecam.applyMovement( move, True)
|
|
165
|
+ freecam.applyRotation([.0001, 0, .0001],True)
|
|
166
|
+ if own['idlecampos_x'] > (move_len / 2):
|
|
167
|
+ move = [-.0001, 0, 0]
|
|
168
|
+ freecam.applyMovement( move, True)
|
|
169
|
+ freecam.applyRotation([-.0001, 0, -.0001],True)
|
|
170
|
+
|
|
171
|
+ if dict['npause'] == True:
|
|
172
|
+ cont.deactivate(own.actuators['Camera'])
|
|
173
|
+ controlcube['camera'] = 2
|
|
174
|
+ if controlcube['camera'] == 2 and dict['joy_con'] == 1:
|
|
175
|
+ cont.deactivate(own.actuators['Camera'])
|
|
176
|
+ scene.active_camera = freecam
|
|
177
|
+ cont.activate(cube.actuators['freecam'])
|
|
178
|
+ #print('activating camera', freecam)
|
|
179
|
+#####
|
|
180
|
+ #get value 0-100
|
|
181
|
+ lLR = dict['lLR'] / .082 * 100
|
|
182
|
+ lUD = dict['lUD'] / .082 * 100 - 20 / 80
|
|
183
|
+ rLR = dict['rLR'] / .082 * 100 - 20 / 80
|
|
184
|
+ rUD = dict['rUD'] / .082 * 100 - 20 / 80
|
|
185
|
+ lTrig = dict['lTrig'] / .082 * 100 - 20 / 80
|
|
186
|
+ rTrig = dict['rTrig'] / .082 * 100 - 20 / 80
|
|
187
|
+# lBump = dict['lBump']
|
|
188
|
+# rBump = dict['rBump']
|
|
189
|
+
|
|
190
|
+ if lLR < -20:
|
|
191
|
+ lmLR = round((lLR + 20) / 80 * 100, 0)
|
|
192
|
+ elif lLR > 20:
|
|
193
|
+ lmLR = round((lLR - 20) / 80 * 100, 0)
|
|
194
|
+ else: lmLR = 0
|
|
195
|
+
|
|
196
|
+ if lUD > 20:
|
|
197
|
+ lmUD = round((lUD - 20) / 80 * 100, 0)
|
|
198
|
+ elif lUD < -20:
|
|
199
|
+ lmUD = round((lUD + 20) / 80 * 100, 0)
|
|
200
|
+ else: lmUD = 0
|
|
201
|
+
|
|
202
|
+ if rLR < -20:
|
|
203
|
+ rmLR = round((rLR + 20) / 80 * 100, 0)
|
|
204
|
+ elif rLR > 20:
|
|
205
|
+ rmLR = round((rLR - 20) / 80 * 100, 0)
|
|
206
|
+ else: rmLR = 0
|
|
207
|
+
|
|
208
|
+ if rUD > 20:
|
|
209
|
+ rmUD = round((rUD - 20) / 80 * 100, 0)
|
|
210
|
+ elif rUD < -20:
|
|
211
|
+ rmUD = round((rUD + 20) / 80 * 100, 0)
|
|
212
|
+ else: rmUD = 0
|
|
213
|
+
|
|
214
|
+ if lTrig > 3:
|
|
215
|
+ mTrig = lTrig * -1
|
|
216
|
+ elif rTrig > 3:
|
|
217
|
+ mTrig = rTrig
|
|
218
|
+ else: mTrig = 0
|
|
219
|
+
|
|
220
|
+ #move camera
|
|
221
|
+ damping = .95
|
|
222
|
+ damping2 = 1.005
|
|
223
|
+ mult = .0005 * own['speed_mult']
|
|
224
|
+ move_x = lmUD * mult
|
|
225
|
+ move_y = lmLR * mult
|
|
226
|
+ move_z = (mTrig * -mult) / 2#4
|
|
227
|
+
|
|
228
|
+ rot_mult = -.00015 * own['speed_mult']
|
|
229
|
+ rot_x = rmUD * rot_mult
|
|
230
|
+ rot_y = rmLR * rot_mult
|
|
231
|
+
|
|
232
|
+ if move_x == 0 and own['last_move_x'] != 0:
|
|
233
|
+ move_x = own['last_move_x'] * damping
|
|
234
|
+ if move_y == 0 and own['last_move_y'] != 0:
|
|
235
|
+ move_y = own['last_move_y'] * damping
|
|
236
|
+ if move_z == 0 and own['last_move_z'] != 0:
|
|
237
|
+ move_z = own['last_move_z'] * damping
|
|
238
|
+ if rot_x == 0 and own['last_rot_x'] != 0:
|
|
239
|
+ rot_x = own['last_rot_x'] * damping
|
|
240
|
+ if rot_y == 0 and own['last_rot_y'] != 0:
|
|
241
|
+ rot_y = own['last_rot_y'] * damping
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+ move = [move_y, 0, move_x]
|
|
245
|
+ freecam.applyMovement( move, True)
|
|
246
|
+ freecam.applyMovement([0, 0, move_z], False)
|
|
247
|
+ freecam.applyRotation([rot_x, 0, 0],True)
|
|
248
|
+ freecam.applyRotation([0, 0, rot_y],False)
|
|
249
|
+
|
|
250
|
+# mult = .1 #* own['speed_mult']
|
|
251
|
+# if lBump == True and own['lBump'] == False:
|
|
252
|
+# if own['speed_mult'] > .1:
|
|
253
|
+# own['speed_mult'] = round(own['speed_mult'] - mult, 2)
|
|
254
|
+# if rBump == True and own['rBump'] == False:
|
|
255
|
+# if own['speed_mult'] < 5.5:
|
|
256
|
+# own['speed_mult'] = round(own['speed_mult'] + mult, 2)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+################
|
|
261
|
+ #print(dict['walk'], 'walk')
|
|
262
|
+ multer = .02
|
|
263
|
+ if dict['walk'] == 1:
|
|
264
|
+ if dict['cur_ccH_targetHeight'] < .8:
|
|
265
|
+ dist = .8 - dict['cur_ccH_targetHeight']
|
|
266
|
+
|
|
267
|
+ dict['cur_ccH_targetHeight'] = dict['cur_ccH_targetHeight'] + (dist * multer)
|
|
268
|
+ if dict['cur_ccH_targetHeight'] > .799:
|
|
269
|
+ dict['cur_ccH_targetHeight'] = .8
|
|
270
|
+ #ccH_targetHeight = .9
|
|
271
|
+ else:
|
|
272
|
+
|
|
273
|
+ if dict['cur_ccH_targetHeight'] < dict['cch_targetHeight']:
|
|
274
|
+ dist = dict['cur_ccH_targetHeight'] - dict['cch_targetHeight']
|
|
275
|
+ dict['cur_ccH_targetHeight'] = dict['cur_ccH_targetHeight'] - (dist * multer)
|
|
276
|
+ if dict['cur_ccH_targetHeight'] > dict['cch_targetHeight'] - .001:
|
|
277
|
+ dict['cur_ccH_targetHeight'] = dict['cch_targetHeight']
|
|
278
|
+
|
|
279
|
+ if dict['cur_ccH_targetHeight'] > dict['cch_targetHeight']:
|
|
280
|
+ dist = dict['cch_targetHeight'] - dict['cur_ccH_targetHeight']
|
|
281
|
+ dict['cur_ccH_targetHeight'] = dict['cur_ccH_targetHeight'] + (dist * multer)
|
|
282
|
+ if dict['cur_ccH_targetHeight'] < dict['cch_targetHeight'] + .001:
|
|
283
|
+ dict['cur_ccH_targetHeight'] = dict['cch_targetHeight']
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+ ccH_targetHeight = dict['cur_ccH_targetHeight']
|
|
287
|
+ #print(dict['cur_ccH_targetHeight'])
|
|
288
|
+ #dict['cur_ccH_targetHeight'] =
|
|
289
|
+ #ccH_targetHeight = .3
|
|
290
|
+ ccH = camCube.worldPosition.z
|
|
291
|
+ pH = camCube.parent.worldPosition.z
|
|
292
|
+ ccheight = (round((ccH - pH), 2) - .4)
|
|
293
|
+ #print(ccheight, 'camera target height')
|
|
294
|
+
|
|
295
|
+ localPos = camCube.localPosition.z
|
|
296
|
+ #print(localPos, 'local position')
|
|
297
|
+ if localPos != ccH_targetHeight:
|
|
298
|
+ num = ccH_targetHeight - localPos
|
|
299
|
+ camCube.localPosition.z += num
|
|
300
|
+ #if camHeightSet not in own:
|
|
301
|
+ if 1 == 1:
|
|
302
|
+ #if ccheight != ccH_targetHeight:
|
|
303
|
+ num = ccH_targetHeight - ccheight
|
|
304
|
+ #camCube.worldPosition.x = controlcube.worldPosition.x
|
|
305
|
+ #camCube.worldPosition.y = controlcube.worldPosition.y
|
|
306
|
+ #camCube.worldPosition.z = controlcube.worldPosition.z + num
|
|
307
|
+ else:
|
|
308
|
+ own['camHeightSet'] = True
|
|
309
|
+
|
|
310
|
+ if dict['npause'] == False:
|
|
311
|
+ cont.activate(own.actuators['Camera'])
|
|
312
|
+ controlcube['camera'] = 0
|
|
313
|
+main()
|