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

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