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 27KB

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