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

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