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

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