shuvit vor 6 Jahren
Ursprung
Commit
e48785970e
1 geänderte Dateien mit 738 neuen und 0 gelöschten Zeilen
  1. 738
    0
      grindV2.py

+ 738
- 0
grindV2.py Datei anzeigen

@@ -0,0 +1,738 @@
1
+import bge
2
+import math
3
+
4
+def main():
5
+    cont = bge.logic.getCurrentController()
6
+    own = cont.owner
7
+    player = cont.owner
8
+    scene = bge.logic.getCurrentScene()
9
+    #grindDar = cont.sensors['grindDar']
10
+    grindEmpty = scene.objects['grindEmpty']
11
+    grindDar = grindEmpty.sensors['grindDar2']    
12
+    rGround = cont.sensors['r_Ground']
13
+    control_bottom = scene.objects['control_bottom']
14
+    #grindCol_bottom 
15
+    grindTouch = control_bottom.sensors['grindCol_bottom']
16
+    #grindTouch = cont.sensors['grindCol']
17
+    invertCol = cont.sensors['invertCol']
18
+    invertObjs = invertCol.hitObjectList
19
+    detectedObjects = grindDar.hitObjectList
20
+    lastObject = own['grindTrackObj']
21
+    nearestObject = None
22
+    minDist = None
23
+    #act = cont.actuators["Target"]
24
+    test = own["test"]
25
+    grindold = own["grindOld"]
26
+    lgobj = own["lGobj"]
27
+    countdown = own['grindCountdown'] 
28
+    #print(lgobj)
29
+    ray = cont.sensors["GuardDuty"] # get the ray sensor attached to the controller named GuardDuty
30
+    gt_cd = own["gt_cd"]
31
+    pos = ray.hitPosition # get position where the game object hit by ray
32
+    linVelocity = own.getLinearVelocity(False)
33
+    linVelocity2 = own.getLinearVelocity(True)
34
+    pos[2] = pos[2] + 1 
35
+    norm = ray.hitNormal
36
+    STANCE = own["stance"]
37
+    orientation = own.worldOrientation
38
+    test = ray.hitObject
39
+    xyz = own.worldOrientation.to_euler()
40
+    rotz = math.degrees(xyz[2])
41
+    roty = math.degrees(xyz[1]) 
42
+    #print(roty)
43
+    roty = abs(roty) 
44
+    sub = 0
45
+    align_strength = 1
46
+    align_strength2 = .3
47
+    touched = grindTouch.triggered
48
+    lgf = own['last_grind_frame']
49
+    gsf = own['grind_start_frame']
50
+    framenum = own['framenum']
51
+    last_ground_frame = own['lF_ground_frame']
52
+    frames_since_ground = framenum - last_ground_frame
53
+    frames_since_grind = framenum - lgf
54
+    #if framenum - lgf > 60:
55
+    minus = framenum - gsf
56
+    grindspeed_rail = .996 #multiplied by current speed
57
+    grindspeed_cement = .995 #multiplied by current speed
58
+    grindDar_timer = own["grindDar_timer"]
59
+    last_grindDar = 0
60
+    last_manual = own["manual"]
61
+    joinit = 0
62
+    #print(minus)
63
+#    if grindold == True and minus > 20:
64
+#        align_strength = .1
65
+#        print("slow align")
66
+
67
+    rot = own.getAxisVect( [0.0, 0.0, 1.0])
68
+    dropin = own['dropinTimer']
69
+    nearestObject = None
70
+    last_hit = own['grindDar_hit']
71
+    jump_timer = own['jump_timer']
72
+    grind_jump = own['grind_jump']
73
+    lastGround = own['lF_ground2']
74
+    OG_PLAYER_POS = own.worldPosition
75
+    grindvect = None
76
+    grindyvect = None
77
+    skipcol = 0
78
+    skipconst = 0
79
+    #print("--------frame: ", own['framenum'])
80
+    #inertia = player.linearVelocity
81
+    #print(rotz)
82
+
83
+    #no grind
84
+    no_grind = 0
85
+    if jump_timer > 50:
86
+        no_grind = 1
87
+    
88
+    #check manual
89
+
90
+    manual = 0
91
+    own["nogrindsound"] = 0
92
+    #print(frames_since_ground)
93
+    #print("grindold: ", grindold)
94
+    
95
+    
96
+    
97
+#---------###########___###########-----------    
98
+#start new                     #######     
99
+##----------##############----------############
100
+
101
+#grindvect func
102
+    grindvect = None
103
+    grindyvect = None
104
+    lastobj = own["grindTouchobj"]
105
+    grindpos = own["grindpos"]
106
+    player_e = own.worldOrientation.to_euler()
107
+    player_rotz = math.degrees(player_e[2]) 
108
+    velxb = linVelocity2.x
109
+    player_e = own.worldOrientation.to_euler()
110
+    
111
+    ogrot = own.orientation
112
+    ogrot = player_e
113
+    
114
+    if (framenum - gsf) > 15:
115
+        velx = linVelocity2.x
116
+        vely = linVelocity2.y
117
+        #print("limit speed")
118
+    else:    
119
+        velx = linVelocity2.x
120
+        vely = linVelocity2.y     
121
+    if abs(own['pregrind_vely']) > abs(vely) and own['LAST_GRIND'] == 0:
122
+        convely = own['pregrind_vely']
123
+    else:
124
+        convely = vely  
125
+    def grindvect(obj):
126
+        if obj != None:
127
+            grinder_e = obj.worldOrientation.to_euler()
128
+            grinder_rotz = math.degrees(grinder_e[2])            
129
+            rot = player_rotz - grinder_rotz
130
+        if rot >= 0 and rot < 45: 
131
+            grindvect = "pos"
132
+        if rot >= 45 and rot < 90: 
133
+            grindvect = "pos" 
134
+            grindyvect = "pos"
135
+        if rot >= 90 and rot < 135: 
136
+            grindvect = "neg"
137
+            grindyvect = "neg"
138
+        if rot >= 135 and rot < 180: 
139
+            grindvect = "neg"
140
+        if rot >= 180 and rot < 225: 
141
+            grindvect = "neg"
142
+        if rot >= 225 and rot < 270: 
143
+            grindvect = "neg"
144
+            grindyvect = "pos"
145
+        if rot >= 270 and rot < 315: 
146
+            grindvect = "pos" 
147
+            grindyvect = "neg"
148
+        if rot >= 315: grindvect = "pos"
149
+        
150
+        if rot < 0 and rot >= -45: 
151
+            grindvect = "pos"
152
+        if rot < -45 and rot >= -90: 
153
+            grindvect = "pos"
154
+            grindyvect = "neg"
155
+        if rot < -90 and rot >= -135: 
156
+            grindvect = "neg"
157
+            grindyvect = "pos"
158
+        if rot < -135 and rot >= -180: 
159
+            grindvect = "neg"  
160
+        if rot < -180 and rot >= -225: 
161
+            grindvect = "neg" 
162
+        if rot < -225 and rot >= -270: 
163
+            grindvect = "neg"
164
+            grindyvect = "neg"
165
+        if rot < -270 and rot >= -315: 
166
+            grindvect = "pos" 
167
+            grindyvect = "pos"
168
+        if rot < -315: 
169
+            grindvect = "pos"         
170
+
171
+    def grindrotvel(obj):        
172
+        skipconst = 1
173
+        #print("set jumponinit")              
174
+        joinit = 0
175
+        grinder_e = obj.worldOrientation.to_euler()
176
+        grinder_rotz = math.degrees(grinder_e[2]) 
177
+        grinder_vect = obj.getAxisVect( [1, 0, 0]) 
178
+        grinder_vectz = obj.getAxisVect( [0, 0, 1]) 
179
+        rot = player_rotz - grinder_rotz        
180
+        rayhit = ray.hitObject
181
+        #print(round(rot,2), STANCE, " = rotation") 
182
+        own['grind_rot'] = rot
183
+        vect = obj.getAxisVect( [1.0, 0.0, 0.0])
184
+        xyzb = obj.worldOrientation.to_euler()
185
+        rotzb = math.degrees(xyzb[2])   
186
+        grindpos = "None"         
187
+        align = "None"
188
+        sub_converted = 0
189
+        rotz = math.degrees(xyz[2])
190
+        roty = math.degrees(xyz[1])
191
+        bsrot = [ 0.0, 0.0, 1.570796327]    
192
+        negbsrot = [ 0.0, 0.0, -1.570796327]
193
+        zvel = own.linearVelocity
194
+        zvel = zvel.z * .95      
195
+        #print(rot, "rot")
196
+        if grindold == 0:
197
+            if rotz < 0:
198
+                rotz = rotz + 360
199
+            if rotzb < 0:
200
+                rotzb = rotzb + 360    
201
+            if rotz > rotzb:
202
+                sub_converted = rotz - rotzb
203
+            if rotz < rotzb:
204
+                sub_converted = rotzb - rotz
205
+
206
+        #print("J grindvect: ", grindvect, "align: ", align)
207
+        #z align
208
+        #print("zalign") 
209
+        player.alignAxisToVect(grinder_vectz, 2, .5)                                                  
210
+        
211
+        if rot >= 0 and rot < 45:
212
+            player.alignAxisToVect(grinder_vect, 0, align_strength)
213
+            grindvect = "pos"
214
+            #player.applyForce([0, 0, 0], True)            
215
+            player.setLinearVelocity([velxb, 0.0, zvel], 1)  
216
+            grindpos = "reg_5050"
217
+
218
+
219
+        if rot >= 45 and rot < 90:  
220
+                             
221
+            player.alignAxisToVect(grinder_vect, 0, align_strength) 
222
+            grindvect = "pos"
223
+            player.applyRotation(bsrot, 1)
224
+            align = "pos"
225
+            #player.applyForce([0, 0, 0], True)
226
+            player.setLinearVelocity([0, convely, zvel], 1)   
227
+            grindpos = "reg_board"     
228
+            grindyvect = "pos"
229
+            #(print("bs1, don't switch")       
230
+            #print("boardslide")
231
+                           
232
+        if rot >= 90 and rot < 135:  
233
+            #print(STANCE, "2")                 
234
+            player.alignAxisToVect(-grinder_vect, 0, align_strength) 
235
+            grindvect = "neg"
236
+            player.applyRotation(negbsrot, 1)
237
+            align = "neg"
238
+            grindyvect = "neg"
239
+            #player.applyForce([0, 0, 0], True)
240
+            player.setLinearVelocity([0, convely, zvel], 1)
241
+            grindpos = "reg_board"  
242
+            #(print("-bs2, don't switch?")          
243
+            #print("boardslide") 
244
+                     
245
+        if rot >= 135 and rot < 180:
246
+            player.alignAxisToVect(-grinder_vect, 0, align_strength)
247
+            grindvect = "neg"
248
+            #player.applyForce([0, 0, 0], True)
249
+            player.setLinearVelocity([velxb, 0.0, zvel], 1) 
250
+            grindpos = "reg_5050"
251
+           
252
+        if rot >= 180 and rot < 225:
253
+            player.alignAxisToVect(-grinder_vect, 0, align_strength)
254
+            grindvect = "neg"
255
+            #player.applyForce([0, 0, 0], True)
256
+            player.setLinearVelocity([velxb, 0.0, zvel], 1)
257
+            grindpos = "reg_5050" 
258
+            
259
+        if rot >= 225 and rot < 270:
260
+            #print(STANCE, "3")
261
+            player.alignAxisToVect(-grinder_vect, 0, align_strength)
262
+            grindvect = "neg"
263
+            player.applyRotation(bsrot, 1)
264
+            align = "pos"
265
+            #player.applyForce([0, 0, 0], True)
266
+            player.setLinearVelocity([0, convely, zvel], 1)
267
+            grindpos = "reg_board"
268
+            grindyvect = "pos"
269
+            #(print("bs3")             
270
+            #print("boardslide")
271
+           
272
+        if rot >= 270 and rot < 315:
273
+            #print(STANCE, "4")
274
+            player.alignAxisToVect(grinder_vect, 0, align_strength) 
275
+            grindvect = "pos"
276
+            player.applyRotation(negbsrot, 1)  
277
+            align = "neg"
278
+            #player.applyForce([0, 0, 0], True)
279
+            player.setLinearVelocity([0, convely, zvel], 1)
280
+            grindpos = "reg_board"   
281
+            grindyvect = "neg"
282
+            #(print("-bs4")              
283
+            #print("boardslide")
284
+            
285
+        if rot >= 315:
286
+            player.alignAxisToVect(grinder_vect, 0, align_strength)
287
+            grindvect = "pos"
288
+            #player.applyForce([0, 0, 0], True)
289
+            player.setLinearVelocity([velxb, 0.0, zvel], 1)
290
+            grindpos = "reg_5050"
291
+                         
292
+#-------------------------------------------------------------            
293
+        if rot < 0 and rot >= -45:
294
+            player.alignAxisToVect(grinder_vect, 0, align_strength)
295
+            grindvect = "pos"
296
+            #player.applyForce([0, 0, 0], True)
297
+            player.setLinearVelocity([velxb, 0.0, zvel], 1)  
298
+            grindpos = "reg_5050"   
299
+                                  
300
+        if rot < -45 and rot >= -90:
301
+            #print(STANCE, "5")
302
+            player.alignAxisToVect(grinder_vect, 0, align_strength)
303
+            grindvect = "pos"
304
+            player.applyRotation(negbsrot, 1)
305
+            align = "neg"
306
+            #player.applyForce([0, 0, 0], True)
307
+            player.setLinearVelocity([0, convely, zvel], 1)
308
+            grindpos = "reg_board"   
309
+            #(print("-bs5")           
310
+            #print("boardslide")
311
+            
312
+            grindyvect = "neg"
313
+        if rot < -90 and rot >= -135:
314
+            #print(STANCE, "6")
315
+            player.alignAxisToVect(-grinder_vect, 0, align_strength) 
316
+            grindvect = "neg"
317
+            player.applyRotation(bsrot, 1)
318
+            align = "pos"
319
+            #player.applyForce([0, 0, 0], True)
320
+            player.setLinearVelocity([0, convely, zvel], 1)
321
+            grindpos = "reg_board"  
322
+            grindyvect = "pos"
323
+            #(print("bs6")           
324
+            #print("boardslide") 
325
+                                           
326
+        if rot < -135 and rot >= -180:
327
+            player.alignAxisToVect(-grinder_vect, 0, align_strength)
328
+            grindvect = "neg"   
329
+            #player.applyForce([0, 0, 0], True)
330
+            player.setLinearVelocity([velxb, 0.0, zvel], 1)  
331
+            grindpos = "reg_5050" 
332
+                       
333
+        if rot < -180 and rot >= -225:
334
+            player.alignAxisToVect(-grinder_vect, 0, align_strength) 
335
+            grindvect = "neg"           
336
+            #player.applyForce([0, 0, 0], True)
337
+            player.setLinearVelocity([velxb, 0.0, zvel], 1)  
338
+            grindpos = "reg_5050" 
339
+        if rot < -225 and rot >= -270:
340
+            #print(STANCE, "7")
341
+            player.alignAxisToVect(-grinder_vect, 0, align_strength) 
342
+            grindvect = "neg"
343
+            player.applyRotation(negbsrot, 1)
344
+            align = "neg"
345
+            #player.applyForce([0, 0, 0], True)
346
+            player.setLinearVelocity([0, convely, zvel], 1)
347
+            grindpos = "reg_board"   
348
+            grindyvect = "neg"
349
+            #(print("-bs7")          
350
+            #print("boardslide")            
351
+        if rot < -270 and rot >= -315:
352
+            #print(STANCE, "8")
353
+            player.alignAxisToVect(grinder_vect, 0, align_strength) 
354
+            grindvect = "pos"
355
+            player.applyRotation(bsrot, 1)
356
+            align = "pos"
357
+            #player.applyForce([0, 0, 0], True)
358
+            player.setLinearVelocity([0, convely, zvel], 1)
359
+            grindpos = "reg_board"    
360
+            grindyvect = "pos"
361
+            #(print("bs8")        
362
+            #print("boardslide")                                
363
+        if rot < -315:
364
+            player.alignAxisToVect(grinder_vect, 0, align_strength) 
365
+            grindvect = "pos"                     
366
+            #player.applyForce([0, 0, 0], True)
367
+            player.setLinearVelocity([velxb, 0.0, zvel], 1)  
368
+            grindpos = "reg_5050"  
369
+
370
+        own['grindpos'] = grindpos
371
+        own['grindvect'] = grindvect
372
+        own['grindervect'] = grinder_vect
373
+        try:   
374
+            own['grindyvect'] = grindyvect
375
+            
376
+        except:
377
+            pass 
378
+                
379
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@        
380
+    def grind(obj):
381
+        #if (ray.triggered and grindold == False) or (touched == True and own['lastTouched'] == False):
382
+        #print("gt: ", gt_cd)
383
+        try:
384
+            grindyvect = own['grindyvect']
385
+        except:
386
+            grindyvect = 0 
387
+        grindvect = own['grindvect'] 
388
+        
389
+        if 'rail' in obj:
390
+            own["grindSound"] = "rail" 
391
+        else:
392
+            own["grindSound"] = "concrete"
393
+        own['lGobj'] = obj         
394
+        
395
+        
396
+        #if 1 == 1:
397
+        grinding = 1                
398
+        
399
+        framenum = own['framenum']
400
+        lastairframe = own['lF_air_frame']
401
+        jumpside = 0
402
+        if (framenum - lastairframe) < 10:
403
+        #if lastGround == False:
404
+            player_pos = own['jumpPos']
405
+            #print("get side from jumpPos", framenum, lastairframe) 
406
+            jumpside = 1   
407
+        else:    
408
+            player_pos = OG_PLAYER_POS
409
+        player_pos = own.worldPosition    
410
+        try:    
411
+            if 1 == 1:       
412
+                
413
+                grinder_pos = obj.worldPosition 
414
+                    #print("touchObj", obj)     
415
+                #vectTo = player.getVectTo(grinder_pos)    
416
+                worldVect = [1, 0, 0]
417
+                vect = obj.getAxisVect(worldVect)      
418
+                go = obj.worldOrientation
419
+                grinder_axis = [0,1,0]
420
+                try: 
421
+                    delta = player_pos - grinder_pos
422
+                except:
423
+                    #print("delta broke: ", player_pos, grinder_pos)
424
+                    pass 
425
+                delta = delta.cross(vect)
426
+                #print(own["grindpos"], touched, "eval broken!!?!", delta[2])
427
+                if delta[2] >= 0:
428
+                    #print("right side", grindyvect, round(delta[2], 6))
429
+                    grindside = "right"
430
+                else:
431
+                    #print("left side", grindyvect, round(delta[2], 6))
432
+                    grindside = "left"
433
+                if (delta[2] > .00001 or delta[2] < -.00001) and (delta[2] < .8 or delta[2] < -.8):
434
+                    rotation = own.worldOrientation[2] - obj.worldOrientation[2]
435
+                    player_e = own.worldOrientation.to_euler()
436
+                    player_rotz = math.degrees(player_e[2])
437
+                    grinder_e = obj.worldOrientation.to_euler()
438
+                    grinder_rotz = math.degrees(grinder_e[2])
439
+                    #print("rotation =", player_rotz - grinder_rotz)
440
+                    #print( "rotating - grindvect: ", grindvect)
441
+                    deltamove = delta[2] * .3#.25
442
+                    #5050
443
+                    #print(own["grindpos"], jumpside)
444
+                    #print("delta move")
445
+                    if own["grindpos"] == "reg_5050":
446
+                        #print("missing delta")
447
+                        if (jumpside == 1 or jumpside == 0) and grindvect == "pos":
448
+                            move = [0, deltamove, 0]
449
+                            #print("1deltamove", deltamove)
450
+                            own.applyMovement(move, True)    
451
+                        if (jumpside == 1 or jumpside == 0) and grindvect == "neg":
452
+                            move = [0, -deltamove, 0]
453
+                            #print("2deltamove -", deltamove)
454
+                            own.applyMovement(move, True)  
455
+                    #board
456
+                    #print("turnud: ", own["turnud"], "grindyvect: ", grindyvect)
457
+                    if own["grindpos"] == "reg_board":
458
+                        if grindvect == "neg":
459
+                            if (jumpside == 1 or jumpside == 0) and grindyvect == "pos":
460
+                                move = [-deltamove, 0, 0]
461
+                                #print("3deltamove", deltamove)
462
+                                own.applyMovement(move, True)        
463
+                            if (jumpside == 1 or jumpside == 0) and grindyvect == "neg":
464
+                                move = [deltamove, 0, 0]
465
+                                #print("4deltamove -", deltamove)
466
+                                own.applyMovement(move, True)            
467
+                        if grindvect == "pos":
468
+                            if (jumpside == 1 or jumpside == 0) and grindyvect == "pos":
469
+                                move = [deltamove, 0, 0]
470
+                                #print("5deltamove", deltamove)
471
+                                own.applyMovement(move, True)        
472
+                            if (jumpside == 1 or jumpside == 0) and grindyvect == "neg":
473
+                                move = [-deltamove, 0, 0]
474
+                                #print("6deltamove -", deltamove)
475
+                                own.applyMovement(move, True)                    
476
+                own['grindside'] = grindside    
477
+        except:
478
+            pass
479
+        #speed limit    
480
+        velo = own.getLinearVelocity(True)
481
+        touchobj = obj
482
+        if touchobj != None and gt_cd == 0:       
483
+            if 'rail' in touchobj:
484
+                newvelx = velo.x * grindspeed_rail   
485
+                newvely = velo.y * grindspeed_rail
486
+                #print("grindspeed limit rail")
487
+            else:
488
+                newvelx = velo.x * grindspeed_cement  
489
+                newvely = velo.y * grindspeed_cement            
490
+            #print("grindspeed limit cement")
491
+            #print("setting newvely =", newvely)
492
+            player.setLinearVelocity([newvelx, newvely, velo.z], 1) 
493
+            #print("grindspeedlimit")  
494
+            player_rot = own.worldOrientation[2]
495
+            grinder_rot = touchobj.worldOrientation[2]
496
+            player_rot = own.getAxisVect( [0.0, 0.0, 1.0])
497
+            xyz3 = own.worldOrientation.to_euler()
498
+            player_rot = math.degrees(xyz3[2])
499
+            xyz4 = touchobj.worldOrientation.to_euler()
500
+            grinder_rot = math.degrees(xyz4[2]) 
501
+            if player_rot < 0:
502
+                player_rot = abs(player_rot) + 180
503
+            if grinder_rot < 0:
504
+                grinder_rot = abs(grinder_rot) + 180                   
505
+            subtraction = player_rot - grinder_rot
506
+
507
+            
508
+    #else:
509
+        #own['grind_rot'] = None 
510
+               
511
+            
512
+    
513
+    if grindDar.positive == False and grindTouch.positive and grindold == 0 and dropin == 0 and grind_jump == 0 and own["grindoutturn"] == 0 and gt_cd == 0 and manual == 0 and no_grind == 0 and nearestObject != lastObject and own['grindjumpturn'] == 0 and own['gt_cd2'] == 0:
514
+        print("touching, no dar")
515
+    #print(grindold, "grindold")        
516
+    if grindDar.positive:
517
+        detectedObjects = grindDar.hitObjectList
518
+        dist = 0
519
+        for obj in detectedObjects:
520
+            dist = own.getDistanceTo(obj)
521
+            if (minDist is None or dist < minDist):
522
+                nearestObject = obj
523
+                minDist = dist     
524
+        #print(dist, nearestObject, "grindDar")
525
+        
526
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@        
527
+        #init grind
528
+
529
+        grind_dist = .8#.6
530
+        if dist < grind_dist and grindold == 0 and dropin == 0 and grind_jump == 0 and own["grindoutturn"] == 0 and gt_cd == 0 and manual == 0 and no_grind == 0 and nearestObject != lastObject and own['grindjumpturn'] == 0 and own['gt_cd2'] == 0:
531
+        #if grindold == 0 and dropin == 0 and grind_jump == 0 and manual == 0 and no_grind == 0 and nearestObject != lastObject:    
532
+            print("new grind trigger")           
533
+            npos = nearestObject.worldPosition
534
+            #own.worldPosition = [npos.x, npos.y, npos.z + .251]
535
+            
536
+            #own.applyMovement([0,0,.05], False)
537
+
538
+
539
+#        grind_height_dif = (own.worldPosition[2] - nearestObject.worldPosition[2]) - .287
540
+
541
+#        if grind_height_dif < 0:
542
+#            newz = (own.worldPosition[2] + abs(grind_height_dif) + .05)
543
+#            own.worldPosition = [own.worldPosition[0],own.worldPosition[1], newz]
544
+#            print(newz, "new")
545
+
546
+        #grind
547
+        #print(dist)
548
+        if dist < grind_dist and dropin == 0 and grind_jump == 0 and manual == 0 and no_grind == 0 and own['airup'] == 0 and own['grindoutturn'] == 0 and own['grindjumpturn'] == 0 and own['manual'] == 0 and own['gt_cd2'] < 50:
549
+            #print("grind")    
550
+            hitObject, hitPoint, hitNormal = own.rayCast(nearestObject.worldPosition, own.worldPosition, .0, 'grind')
551
+            if grindold == 0:
552
+                if grindTouch.positive:
553
+                    print("set grind pos")
554
+                    nearpos = nearestObject.worldPosition
555
+                    if hitNormal != None:
556
+                        own.alignAxisToVect(hitNormal, 2, 1) 
557
+                        print("align")                   
558
+                    #own.worldPosition = [nearpos.x, nearpos.y, nearpos.z + .2975]
559
+                    print("setting pos")
560
+            
561
+            #if hitNormal != None:
562
+                #own.alignAxisToVect(hitNormal, 2, .4)
563
+                #print(hitNormal)
564
+
565
+
566
+
567
+         
568
+            grindold = True
569
+            own['grindold_timer'] = 0
570
+            own["grindHit"] = True
571
+            #print("grinding")
572
+            grind_height_dif = (own.worldPosition[2] - nearestObject.worldPosition[2]) - .287
573
+            #print(grind_height_dif)
574
+            worldPos = own.worldPosition
575
+            if grind_height_dif > -.02:
576
+                #print("############################upping z")
577
+                #own.worldPosition = [worldPos.x, worldPos.y, worldPos.z + .1]
578
+
579
+                grindvect(nearestObject)          
580
+                grindrotvel(nearestObject)
581
+                grind(nearestObject)
582
+
583
+
584
+    else:
585
+        #grindold = False 
586
+        own['grindold_timer'] += 1
587
+        own["grindHit"] = False
588
+           
589
+    
590
+    if own['grindold_timer'] > 5:
591
+        grindold = False
592
+        own["grindSound"] = None
593
+    
594
+    
595
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    
596
+    
597
+#if you are touching grinder and last_manual is off keep manual off
598
+    if (own['fak_nmanual'] == 1 or own['reg_nmanual'] == 1 or own['fak_manual'] == 1 or own['reg_manual'] == 1) and lastGround == True and grindold == False:
599
+        manual = 1
600
+        if last_manual == 0 and grindTouch.triggered == True:
601
+            manual = 0
602
+        own["nogrindsound"] = 1
603
+    grindhit = own["grindHit"]
604
+
605
+    if abs(own['pregrind_vely']) > abs(vely) and own['LAST_GRIND'] == 0:
606
+        convely = own['pregrind_vely']
607
+    else:
608
+        convely = vely    
609
+
610
+    off = 0
611
+
612
+    if touched == True:
613
+        own["grindTouchobj"] = grindTouch.hitObject
614
+    else:
615
+        own["grindTouchobj"] = None  
616
+ 
617
+    if ray.triggered and dropin == 0:
618
+        lgobj = ray.hitObject
619
+        own['lGobj'] = lgobj
620
+        obj = ray.hitObject
621
+        #prop = obj.get("property", None)
622
+        linVelocity3 = own.getLinearVelocity(True)
623
+        grindpos2 = own["grindpos"]
624
+        regboard = "reg_board"
625
+        fakboard = "fak_board"
626
+        if obj is not None:        
627
+            if 'rail' in ray.hitObject:
628
+                own["grindSound"] = "rail" 
629
+            else:
630
+                own["grindSound"] = "concrete"
631
+        own['lGobj'] = lgobj    
632
+    else:
633
+        lgobj = "empty"
634
+        own['lGobj'] = lgobj
635
+    def timer():
636
+        countdown = own["grindCountdown"]
637
+        if touched == 1:
638
+            countdown = 20
639
+        else:
640
+            countdown = countdown - 1
641
+        own['grindCountdown'] = countdown
642
+    def aligntimer():
643
+        if own['grindOld'] == 0 and ray.triggered == 1:
644
+            own['aligntimer'] = 20
645
+        if own['grindOld'] == 1 and ray.triggered == 1:
646
+            own['aligntimer'] = own['aligntimer'] - 1
647
+        if own['grindOld'] == 0 and ray.triggered == 0:
648
+            own['aligntimer'] = 0   
649
+            
650
+    def invertpos():
651
+        minDist = None
652
+        nearestObject = None
653
+        for obj in invertObjs:
654
+            dist = own.getDistanceTo(obj)
655
+            if (minDist is None or dist < minDist):
656
+                nearestObject = obj
657
+                minDist = dist
658
+        vect = nearestObject.getAxisVect( [1.0, 0.0, 0.0])
659
+        #own.alignAxisToVect(vect, 0, 0)
660
+        own.worldPosition = [nearestObject.worldPosition.x, nearestObject.worldPosition.y, nearestObject.worldPosition.z +.1]
661
+        #own.setLinearVelocity([0, 0.0, 0], 1)                    
662
+
663
+    def set_pregrind_vel():
664
+        if grindDar.triggered == False and ray.triggered == False:
665
+            #print("set pregrind vel") 
666
+            own['pregrind_velx'] = linVelocity2.x
667
+            own['pregrind_vely'] = linVelocity2.y
668
+            own['pregrind_velz'] = linVelocity2.z
669
+            
670
+    def stop_bounce():
671
+        if grindTouch.triggered and no_grind == 0 and grind_jump == 0 and jump_timer < 30:
672
+            linVelocity4 = own.getLinearVelocity(True)
673
+            #print(linVelocity4.z)
674
+            if linVelocity4.z > 0:
675
+                own.setLinearVelocity([linVelocity4.x, linVelocity4.y, 0], 1)
676
+                        
677
+#        last_posz = own['last_z']
678
+#        posz = own.worldPosition.z
679
+#        obj = None
680
+#        if ray.triggered:
681
+#            obj = ray.hitObject
682
+#        if grindTouch.triggered:
683
+#            obj = grindTouch.hitObject        
684
+#        #if last_posz < posz and grindold == True and obj != None:
685
+#        gsf = own['grind_start_frame']
686
+#        frame = own['framenum']
687
+#        sub = frame - gsf
688
+#        linVelocity4 = own.getLinearVelocity(True)
689
+#        avelx = linVelocity4.x
690
+#        avely = linVelocity4.y
691
+#        avelz = linVelocity4.z
692
+#        num = -.2
693
+#        num2 = -.1
694
+#        if avelz > 0:
695
+#            avelz = 0
696
+#        avelz = avelz + num
697
+#                
698
+#        #if obj != None and sub > 30 and jump_timer < 10:
699
+#            #own.setLinearVelocity([avelx, avely, num2], 1)
700
+#        if sub < 3: 
701
+#            pass
702
+#            #own.setLinearVelocity([avelx, avely, avelz], 1) 
703
+            
704
+              
705
+    if jump_timer < 30 :
706
+        own['grind_jump'] = 0 
707
+    if grindold == False and ray.triggered:
708
+        own['grind_start_frame'] = own['framenum']  
709
+        
710
+    if grindDar_timer > 0:
711
+        grindDar_timer -= 1
712
+    if grindDar_timer > 0 and ray.triggered == False and touched == True  and own['footplant_on'] == False and manual == 0:
713
+        #print("timer but ground") 
714
+        obj = grindTouch.hitObject 
715
+        own.worlPosition = obj.worldPosition
716
+    if ray.triggered == False:
717
+        own["nogrindsound"] = 1                               
718
+    timer()    
719
+    aligntimer()
720
+    stop_bounce()   
721
+                   
722
+    own['grindOld'] = grindold 
723
+    own['test'] = test
724
+    own['grindTrackObj'] = nearestObject
725
+    own['grindDar_hit'] = grindDar.positive
726
+    own['lastTouched'] = touched
727
+    own['grindTouch'] = grindTouch.triggered
728
+    own["grindDar_timer"] = grindDar_timer
729
+    own["last_grindDar"] = last_grindDar
730
+    linVelocity3 = own.getLinearVelocity(True)
731
+    #print(linVelocity3.z)
732
+    set_pregrind_vel()
733
+    own['last_z'] = own.worldPosition.z
734
+    own["manual"] = manual
735
+
736
+
737
+
738
+main()

Laden…
Abbrechen
Speichern