Shuvit game master repo. http://shuvit.org
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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