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

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