Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

grindV2.py 26KB

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