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

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