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

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