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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. lv_green = Vector(found_green[0][0])
  116. eul = Vector((1, 0, 0)).rotation_difference(lineVector).to_euler()
  117. te = scene.objects['temp_empty']
  118. rotation = te.worldOrientation.to_euler()
  119. if abs(rotation.z) > 3:
  120. te.applyRotation([0, 0, 1.570796*2], True)
  121. #te.alignAxisToVect(worldY, 1, 1)
  122. #print(te.worldOrientation, 'world orientation')
  123. xyz = te.localOrientation.to_euler()
  124. xyz[0] = math.radians(0)
  125. te.localOrientation = xyz.to_matrix()
  126. if lineVector == Vector([0.0, 0.0, 0.0]):
  127. #print('vector is empty')
  128. pass
  129. else:
  130. te.alignAxisToVect(lineVector, 0, 1)
  131. te.worldPosition = primary
  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']:
  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("setting stance")
  272. if (rot == 90 or rot == -270) and STANCE == True:
  273. #print("90 fak stance")
  274. own['stance'] = 1
  275. STANCE = 1
  276. if (rot == 90 or rot == -270) and STANCE == False:
  277. #print("90 fak stance")
  278. own['stance'] = 1
  279. STANCE = 1
  280. if (rot == -90 or rot == 270) and STANCE == True:
  281. #print("-90 reg stance")
  282. own['stance'] = 0
  283. STANCE = 0
  284. if (rot == -90 or rot == 270) and STANCE == False:
  285. #print("-90 reg stance")
  286. own['stance'] = 0
  287. STANCE = 0
  288. def grindrotvel(obj):
  289. joinit = 0
  290. grinder_e = obj.worldOrientation.to_euler()
  291. grinder_rotz = math.degrees(grinder_e[2])
  292. grinder_vect = obj.getAxisVect([1, 0, 0])
  293. grinder_vectz = obj.getAxisVect([0, 0, 1])
  294. rot = player_rotz - grinder_rotz
  295. rayhit = ray.hitObject
  296. own['grind_rot'] = rot
  297. vect = obj.getAxisVect([1.0, 0.0, 0.0])
  298. xyzb = obj.worldOrientation.to_euler()
  299. rotzb = math.degrees(xyzb[2])
  300. grindpos = "None"
  301. align = "None"
  302. sub_converted = 0
  303. rotz = math.degrees(xyz[2])
  304. roty = math.degrees(xyz[1])
  305. bsrot = [0.0, 0.0, 1.570796327]
  306. negbsrot = [0.0, 0.0, -1.570796327]
  307. zvel = own.linearVelocity
  308. zvel = zvel.z * .95
  309. if grindold == 0:
  310. if rotz < 0:
  311. rotz = rotz + 360
  312. if rotzb < 0:
  313. rotzb = rotzb + 360
  314. if rotz > rotzb:
  315. sub_converted = rotz - rotzb
  316. if rotz < rotzb:
  317. sub_converted = rotzb - rotz
  318. #z align
  319. stre = .15#.075#.15
  320. #player.alignAxisToVect(grinder_vectz, 2, stre)
  321. if rot >= 0 and rot < 45:
  322. player.alignAxisToVect(grinder_vect, 0, align_strength)
  323. grindvect = "pos"
  324. #player.applyForce([0, 0, 0], True)
  325. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  326. grindpos = "reg_5050"
  327. #print("50-1")
  328. elif rot >= 45 and rot < 90:
  329. player.alignAxisToVect([-grinder_vect.y, grinder_vect.x, 0], 0, align_strength)
  330. grindvect = "pos"
  331. align = "pos"
  332. player.setLinearVelocity([0, convely, zvel], 1)
  333. grindpos = "reg_board"
  334. grindyvect = "pos"
  335. elif rot >= 90 and rot < 135:
  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. grindyvect = "neg"
  341. player.setLinearVelocity([0, convely, zvel], 1)
  342. grindpos = "reg_board"
  343. #print("-bs2, don't switch?")
  344. elif rot >= 135 and rot < 180:
  345. player.alignAxisToVect(-grinder_vect, 0, align_strength)
  346. grindvect = "neg"
  347. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  348. grindpos = "reg_5050"
  349. #print("50-2")
  350. elif rot >= 180 and rot < 225:
  351. player.alignAxisToVect(-grinder_vect, 0, align_strength)
  352. grindvect = "neg"
  353. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  354. grindpos = "reg_5050"
  355. #print("50-3")
  356. elif rot >= 225 and rot < 270:
  357. player.alignAxisToVect([grinder_vect.y, -grinder_vect.x, 0], 0, align_strength)
  358. grindvect = "neg"
  359. align = "pos"
  360. player.setLinearVelocity([0, convely, zvel], 1)
  361. grindpos = "reg_board"
  362. grindyvect = "pos"
  363. #print("bs3")
  364. elif rot >= 270 and rot < 315:
  365. player.alignAxisToVect([grinder_vect.y, -grinder_vect.x, 0], 0, align_strength)
  366. grindvect = "pos"
  367. align = "neg"
  368. player.setLinearVelocity([0, convely, zvel], 1)
  369. grindpos = "reg_board"
  370. grindyvect = "neg"
  371. #print("-bs4")
  372. elif rot >= 315:
  373. player.alignAxisToVect(grinder_vect, 0, align_strength)
  374. grindvect = "pos"
  375. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  376. grindpos = "reg_5050"
  377. #print("50-4")
  378. #-------------------------------------------------------------
  379. elif rot < 0 and rot >= -45:
  380. player.alignAxisToVect(grinder_vect, 0, align_strength)
  381. grindvect = "pos"
  382. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  383. grindpos = "reg_5050"
  384. #print("50-5")
  385. elif rot < -45 and rot >= -90:
  386. grinder_vect = grinder_vect * -1
  387. player.alignAxisToVect([-grinder_vect.y, grinder_vect.x, 0], 0, align_strength)
  388. grindvect = "pos"
  389. align = "neg"
  390. player.setLinearVelocity([0, convely, zvel], 1)
  391. grindpos = "reg_board"
  392. #print("-bs5")
  393. grindyvect = "neg"
  394. elif rot < -90 and rot >= -135:
  395. player.alignAxisToVect([grinder_vect.y, -grinder_vect.x, 0], 0, align_strength)
  396. grindvect = "neg"
  397. align = "pos"
  398. player.setLinearVelocity([0, convely, zvel], 1)
  399. grindpos = "reg_board"
  400. grindyvect = "pos"
  401. #print("bs6")
  402. elif rot < -135 and rot >= -180:
  403. player.alignAxisToVect(-grinder_vect, 0, align_strength)
  404. grindvect = "neg"
  405. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  406. grindpos = "reg_5050"
  407. #print("50-6")
  408. elif rot < -180 and rot >= -225:
  409. player.alignAxisToVect(-grinder_vect, 0, align_strength)
  410. grindvect = "neg"
  411. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  412. grindpos = "reg_5050"
  413. #print("50-7")
  414. elif rot < -225 and rot >= -270:
  415. grinder_vect = grinder_vect * -1
  416. player.alignAxisToVect([grinder_vect.y, -grinder_vect.x, 0], 0, align_strength)
  417. grindvect = "neg"
  418. align = "neg"
  419. player.setLinearVelocity([0, convely, zvel], 1)
  420. grindpos = "reg_board"
  421. grindyvect = "neg"
  422. #print("-bs7")
  423. elif rot < -270 and rot >= -315:
  424. player.alignAxisToVect([-grinder_vect.y, grinder_vect.x, 0], 0, align_strength)
  425. grindvect = "pos"
  426. align = "pos"
  427. player.setLinearVelocity([0, convely, zvel], 1)
  428. grindpos = "reg_board"
  429. grindyvect = "pos"
  430. #print("bs8")
  431. elif rot < -315:
  432. player.alignAxisToVect(grinder_vect, 0, align_strength)
  433. grindvect = "pos"
  434. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  435. grindpos = "reg_5050"
  436. #print("50-8")
  437. own['grindpos'] = grindpos
  438. own['grindvect'] = grindvect
  439. own['grindervect'] = grinder_vect
  440. try:
  441. own['grindyvect'] = grindyvect
  442. except:
  443. pass
  444. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  445. def grind(obj):
  446. try:
  447. grindyvect = own['grindyvect']
  448. except:
  449. grindyvect = 0
  450. grindvect = own['grindvect']
  451. # if 'rail' in obj:
  452. # own["grindSound"] = "rail"
  453. # else:
  454. # own["grindSound"] = "concrete"
  455. own['lGobj'] = obj
  456. grinding = 1
  457. framenum = own['framenum']
  458. lastairframe = own['lF_air_frame']
  459. jumpside = 0
  460. if (framenum - lastairframe) < 10:
  461. player_pos = own['jumpPos']
  462. jumpside = 1
  463. else:
  464. player_pos = OG_PLAYER_POS
  465. player_pos = own.worldPosition
  466. try:
  467. if 1 == 1:
  468. grinder_pos = obj.worldPosition
  469. worldVect = [1, 0, 0]
  470. vect = obj.getAxisVect(worldVect)
  471. grinder_axis = [0, 1, 0]
  472. try:
  473. delta = player_pos - grinder_pos
  474. except:
  475. pass
  476. delta = delta.cross(vect)
  477. if delta[2] >= 0:
  478. grindside = "right"
  479. else:
  480. grindside = "left"
  481. edge = 0
  482. if 'edge' in obj:
  483. edge = 1
  484. #print('grind on', grindside, edge)
  485. if (delta[2] > .00001 or delta[2] < -.00001) and (delta[2] < 1.8 or delta[2] < -1.8):
  486. rotation = own.worldOrientation[2] - obj.worldOrientation[2]
  487. player_e = own.worldOrientation.to_euler()
  488. player_rotz = math.degrees(player_e[2])
  489. grinder_e = obj.worldOrientation.to_euler()
  490. grinder_rotz = math.degrees(grinder_e[2])
  491. deltamove = delta[2] * .3
  492. #5050
  493. if own["grindpos"] == "reg_5050":
  494. #print("missing delta")
  495. if (jumpside == 1 or jumpside == 0) and grindvect == "pos":
  496. move = [0, deltamove, 0]
  497. #print("1deltamove", deltamove)
  498. own.applyMovement(move, True)
  499. if (jumpside == 1 or jumpside == 0) and grindvect == "neg":
  500. move = [0, -deltamove, 0]
  501. #print("2deltamove -", deltamove)
  502. own.applyMovement(move, True)
  503. #board
  504. if own["grindpos"] == "reg_board":
  505. if grindvect == "neg":
  506. if (jumpside == 1 or jumpside == 0) and grindyvect == "pos":
  507. move = [-deltamove, 0, 0]
  508. #print("3deltamove", deltamove)
  509. own.applyMovement(move, True)
  510. if (jumpside == 1 or jumpside == 0) and grindyvect == "neg":
  511. move = [deltamove, 0, 0]
  512. #print("4deltamove -", deltamove)
  513. own.applyMovement(move, True)
  514. if grindvect == "pos":
  515. if (jumpside == 1 or jumpside == 0) and grindyvect == "pos":
  516. move = [deltamove, 0, 0]
  517. #print("5deltamove", deltamove)
  518. own.applyMovement(move, True)
  519. if (jumpside == 1 or jumpside == 0) and grindyvect == "neg":
  520. move = [-deltamove, 0, 0]
  521. own.applyMovement(move, True)
  522. own['grindside'] = grindside
  523. except:
  524. print('something in grinding is wrong')
  525. #pass
  526. #speed limit
  527. velo = own.getLinearVelocity(True)
  528. touchobj = obj
  529. if touchobj != None and gt_cd == 0:
  530. if 'rail' in touchobj:
  531. newvelx = velo.x * grindspeed_rail
  532. newvely = velo.y * grindspeed_rail
  533. else:
  534. newvelx = velo.x * grindspeed_cement
  535. newvely = velo.y * grindspeed_cement
  536. player.setLinearVelocity([newvelx, newvely, velo.z], 1)
  537. player_rot = own.worldOrientation[2]
  538. grinder_rot = touchobj.worldOrientation[2]
  539. player_rot = own.getAxisVect([0.0, 0.0, 1.0])
  540. xyz3 = own.worldOrientation.to_euler()
  541. player_rot = math.degrees(xyz3[2])
  542. xyz4 = touchobj.worldOrientation.to_euler()
  543. grinder_rot = math.degrees(xyz4[2])
  544. if player_rot < 0:
  545. player_rot = abs(player_rot) + 180
  546. if grinder_rot < 0:
  547. grinder_rot = abs(grinder_rot) + 180
  548. subtraction = player_rot - grinder_rot
  549. def invertpos(detectedObjects):
  550. minDist = None
  551. nearestObject = None
  552. for obj in detectedObjects:
  553. dist = own.getDistanceTo(obj)
  554. if (minDist is None or dist < minDist):
  555. nearestObject = obj
  556. minDist = dist
  557. if nearestObject != None:
  558. own.linearVelocity.x = 0
  559. own.linearVelocity.y = 0
  560. #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:
  561. #print("touching, no dar")
  562. #pass
  563. #print(grindold, "grindold")
  564. skipper = 0
  565. if (grindDar.positive or grindTouch.positive) and no_grind == 0:
  566. if grindDar.positive:
  567. detectedObjects = grindDar.hitObjectList
  568. dist = 0.0
  569. for obj in detectedObjects:
  570. #dist = own.getDistanceTo(obj)
  571. if (minDist is None or dist < minDist):
  572. #nearestObject = obj
  573. minDist = dist
  574. #elif grindTouch.positive:
  575. #nearestObject = grindTouch.hitObject
  576. #dist = .7
  577. #print('using touch object')
  578. nearestObject = scene.objects['temp_empty']
  579. dist = own.getDistanceTo(nearestObject)
  580. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  581. #init grind
  582. if invert_on:
  583. invertpos(detectedObjects)
  584. own['inverting'] = True
  585. print('calling invert funct')
  586. else:
  587. own['inverting'] = False
  588. grind_dist = .8#.6
  589. skipper = 0
  590. #print(lastobj.worldPosition)
  591. 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):
  592. #print("grinding")
  593. grind_height_dif = (own.worldPosition[2] - nearestObject.worldPosition[2]) - .287
  594. if grind_height_dif > -.05:#02:
  595. if own['grinder_rot'] != None:
  596. grot = nearestObject.getAxisVect([1, 0.0, 0.0]).x
  597. dif = (grot - own['grinder_rot'])
  598. if dif > .8 or dif < - .8:
  599. print('skipping grind, angle is', dif)
  600. skipper = 1
  601. own['grinder_rot'] = nearestObject.getAxisVect([1, 0, 0]).x
  602. if skipper != 1:
  603. grindvect(nearestObject)
  604. grindrotvel(nearestObject)
  605. grind(nearestObject)
  606. grindold = True
  607. own['grindold_timer'] = 0
  608. own["grindHit"] = True
  609. own['grindnew_timer'] += 1
  610. if own['grindnew_timer'] < 1:
  611. if grindTouch.triggered:
  612. nearpos = nearestObject.worldPosition.copy
  613. nearpos.z += .2975
  614. if hitNormal != None:
  615. stre = .15
  616. #own.alignAxisToVect(hitNormal, 2, stre)
  617. #own.worldPosition = [nearpos.x, nearpos.y, nearpos.z + .2975]
  618. own.worldPosition.lerp(own.worldPosition, nearpos, .1)
  619. print('new moving world')
  620. else:
  621. own['grindold_timer'] += 1
  622. own["grindHit"] = False
  623. own['inverting'] = False
  624. if own['grindold_timer'] > 5:
  625. grindold = False
  626. own['grind_start_frame'] = framenum
  627. own["grindSound"] = None
  628. if own['grindHit'] == False:
  629. own['grindnew_timer'] = 0
  630. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  631. #if you are touching grinder and last_manual is off keep manual off
  632. 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:
  633. manual = 1
  634. if last_manual == 0 and grindTouch.triggered == True:
  635. manual = 0
  636. own["nogrindsound"] = 1
  637. grindhit = own["grindHit"]
  638. if abs(own['pregrind_vely']) > abs(vely) and own['LAST_GRIND'] == 0:
  639. convely = own['pregrind_vely']
  640. else:
  641. convely = vely
  642. off = 0
  643. if touched == True:
  644. own["grindTouchobj"] = grindTouch.hitObject
  645. else:
  646. own["grindTouchobj"] = None
  647. if ray.triggered and dropin == 0:
  648. lgobj = ray.hitObject
  649. own['lGobj'] = lgobj
  650. obj = ray.hitObject
  651. linVelocity3 = own.getLinearVelocity(True)
  652. grindpos2 = own["grindpos"]
  653. if obj is not None:
  654. if 'rail' in ray.hitObject:
  655. own["grindSound"] = "rail"
  656. else:
  657. own["grindSound"] = "concrete"
  658. own['lGobj'] = lgobj
  659. else:
  660. lgobj = "empty"
  661. own['lGobj'] = lgobj
  662. def timer():
  663. countdown = own["grindCountdown"]
  664. if touched == 1:
  665. countdown = 20
  666. else:
  667. countdown = countdown - 1
  668. own['grindCountdown'] = countdown
  669. def aligntimer():
  670. if own['grindOld'] == 0 and ray.triggered == 1:
  671. own['aligntimer'] = 20
  672. if own['grindOld'] == 1 and ray.triggered == 1:
  673. own['aligntimer'] = own['aligntimer'] - 1
  674. if own['grindOld'] == 0 and ray.triggered == 0:
  675. own['aligntimer'] = 0
  676. def invertpos(xyz):
  677. minDist = None
  678. nearestObject = None
  679. print('doing invert funct')
  680. for obj in invertObjs:
  681. dist = own.getDistanceTo(obj)
  682. if (minDist is None or dist < minDist):
  683. nearestObject = obj
  684. minDist = dist
  685. vect = nearestObject.getAxisVect([1.0, 0.0, 0.0])
  686. own.worldPosition = [nearestObject.worldPosition.x, nearestObject.worldPosition.y, nearestObject.worldPosition.z +.1]
  687. def set_pregrind_vel():
  688. if grindDar.triggered == False and ray.triggered == False:
  689. own['pregrind_velx'] = linVelocity2.x
  690. own['pregrind_vely'] = linVelocity2.y
  691. own['pregrind_velz'] = linVelocity2.z
  692. def stop_bounce():
  693. if grindTouch.triggered and no_grind == 0 and grind_jump == 0 and jump_timer < 30:
  694. linVelocity4 = own.getLinearVelocity(True)
  695. if linVelocity4.z > 0:
  696. own.setLinearVelocity([linVelocity4.x, linVelocity4.y, 0], 1)
  697. if jump_timer < 30:
  698. own['grind_jump'] = 0
  699. if grindold == False and ray.triggered:
  700. own['grind_start_frame'] = own['framenum']
  701. if grindDar_timer > 0:
  702. grindDar_timer -= 1
  703. 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:
  704. obj = grindTouch.hitObject
  705. try:
  706. nearpos = obj.worldPosition
  707. except:
  708. pass
  709. def slow_roty():
  710. constraint = cont.actuators['gConstraint']
  711. if (own['framenum'] - own['grind_start_frame'] < 40) and touched == 1:
  712. cont.activate(constraint)
  713. else:
  714. cont.deactivate(constraint)
  715. timer()
  716. aligntimer()
  717. stop_bounce()
  718. slow_roty()
  719. own['grindOld'] = grindold
  720. own['test'] = test
  721. own['grindTrackObj'] = nearestObject
  722. own['grindDar_hit'] = grindDar.positive
  723. own['lastTouched'] = touched
  724. own['grindTouch'] = grindTouch.triggered
  725. own["grindDar_timer"] = grindDar_timer
  726. own["last_grindDar"] = last_grindDar
  727. own['last_roty'] = roty
  728. linVelocity3 = own.getLinearVelocity(True)
  729. set_pregrind_vel()
  730. own['last_z'] = own.worldPosition.z
  731. own["manual"] = manual