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

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