暫無描述
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.

joy_cam.py 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import bge
  2. def main():
  3. cont = bge.logic.getCurrentController()
  4. own = cont.owner
  5. aXis = cont.sensors['stickDirections']
  6. reduction = 400000
  7. axisTh = 0.03
  8. lar_lts = 0
  9. uad_lts = 1
  10. lar_rts = 2
  11. uad_rts = 3
  12. lt = 4
  13. rt = 5
  14. a_but = 0
  15. b_but = 1
  16. x_but = 2
  17. y_but = 3
  18. l_bump = 9
  19. r_bump = 10
  20. bk_but = 4
  21. st_but = 6
  22. xb_but = 5
  23. lts_pr = 7
  24. rts_pr = 8
  25. l_dp = 13
  26. r_dp = 14
  27. u_dp = 11
  28. d_dp = 12
  29. lLR = aXis.axisValues[lar_lts] / reduction / .082 * 100
  30. if lLR < -20:
  31. lmLR = round((lLR + 20) / 80 * 100, 0)
  32. elif lLR > 20:
  33. lmLR = round((lLR - 20) / 80 * 100, 0)
  34. else: lmLR = 0
  35. lUD = aXis.axisValues[uad_lts] / reduction / .082 * 100 - 20 / 80
  36. if lUD > 20:
  37. lmUD = round((lUD - 20) / 80 * 100, 0)
  38. elif lUD < -20:
  39. lmUD = round((lUD + 20) / 80 * 100, 0)
  40. else: lmUD = 0
  41. #lmUD = lmUD * -1
  42. rLR = aXis.axisValues[lar_rts] / reduction / .082 * 100 - 20 / 80
  43. if rLR < -20:
  44. rmLR = round((rLR + 20) / 80 * 100, 0)
  45. elif rLR > 20:
  46. rmLR = round((rLR - 20) / 80 * 100, 0)
  47. else: rmLR = 0
  48. rUD = aXis.axisValues[uad_rts] / reduction / .082 * 100 - 20 / 80
  49. if rUD > 20:
  50. rmUD = round((rUD - 20) / 80 * 100, 0)
  51. elif rUD < -20:
  52. rmUD = round((rUD + 20) / 80 * 100, 0)
  53. else: rmUD = 0
  54. #rmUD = rmUD * -1
  55. lTrig = aXis.axisValues[lt] / reduction / .082 * 100 - 20 / 80
  56. rTrig = aXis.axisValues[rt] / reduction / .082 * 100 - 20 / 80
  57. #sens = cont.sensors['stickDirections']
  58. if lTrig > 3:
  59. mTrig = lTrig * -1
  60. elif rTrig > 3:
  61. mTrig = rTrig
  62. else: mTrig = 0
  63. #print(lmTrig)
  64. #move camera
  65. damping = .95
  66. damping2 = 1.005
  67. mult = .0005
  68. move_x = lmUD * mult
  69. move_y = lmLR * mult
  70. move_z = (mTrig * -mult) / 4
  71. rot_mult = -.00005
  72. rot_x = rmUD * rot_mult
  73. rot_y = rmLR * rot_mult
  74. if move_x == 0 and own['last_move_x'] != 0:
  75. move_x = own['last_move_x'] * damping
  76. if move_y == 0 and own['last_move_y'] != 0:
  77. move_y = own['last_move_y'] * damping
  78. #if move_x > 0:
  79. #if own['last_move_x'] < 0 and move_x > own['last_move_x']:
  80. # move_x = own['last_move_x'] * damping
  81. #else:
  82. #move_x = own['last_move_x'] * damping2
  83. #elif move_x < -1 and move_x > own['last_move_x']:
  84. #move_x = own['last_move_x'] * damping
  85. move = [move_y, 0, move_x]
  86. own.applyMovement( move, True)
  87. own.applyMovement([0, 0, move_z], False)
  88. own.applyRotation([rot_x, 0, 0],True)
  89. own.applyRotation([0, 0, rot_y],False)
  90. own['lmLR'] = lmLR
  91. own['lmUD'] = lmUD
  92. own['rmLR'] = rmLR
  93. own['rmUD'] = rmUD
  94. own['mTrig'] = mTrig
  95. own['last_move_x'] = move_x
  96. own['last_move_y'] = move_y
  97. print(move_x)
  98. main()