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

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