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

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