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

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