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.

camera.py 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #zskcam
  2. import bge
  3. import mathutils
  4. from mathutils import *
  5. scene = bge.logic.getCurrentScene()
  6. cont = bge.logic.getCurrentController()
  7. own = cont.owner
  8. def main():
  9. dict = bge.logic.globalDict
  10. camempty = scene.objects['camEmpty.001']
  11. controlcube = scene.objects['control_cube.002']
  12. camCube = scene.objects['camCube']
  13. dropinCol = controlcube.sensors['dropinCol']
  14. LAST_GRIND = controlcube['LAST_GRIND']
  15. up = cont.sensors['up']
  16. ray = cont.sensors['up']
  17. down = cont.sensors['down']
  18. left = cont.sensors['left']
  19. right = cont.sensors['right']
  20. distance = 0.12
  21. cam = cont.actuators["Camera"]
  22. near = cont.sensors["Near"]
  23. move = own.actuators["move"]
  24. #match camera actuaotor
  25. cam_def_height = dict['cam_height'] #-.1 #-.6
  26. #cam_def_min = 1.6
  27. #cam_def_max = 2.4
  28. cam_def_min = dict['cam_min']
  29. cam_def_max = dict['cam_max']
  30. cam_height = cam.height
  31. cam_min = cam.min
  32. cam_max = cam.max
  33. lasty = controlcube['lasty']
  34. cam_moved = 0
  35. lastCamheight = controlcube['lastCamheight']
  36. raised = 0
  37. walk = controlcube['walk']
  38. cam.axis = 4
  39. ccheight = controlcube.worldPosition[2]
  40. camwpz = own.worldPosition[2]
  41. zdist = camwpz - ccheight
  42. cam1 = scene.objects['Camera.003']
  43. cam2 = scene.objects['freecam']
  44. cam3 = scene.objects['followcam']
  45. camList = scene.cameras
  46. freecam = camList["freecam"]
  47. if 'init' not in own:
  48. own['init'] = 1
  49. own['last_move_x'] = 0
  50. own['last_move_y'] = 0
  51. own['last_move_z'] = 0
  52. own['last_rot_x'] = 0
  53. own['last_rot_y'] = 0
  54. own['last_rot_z'] = 0
  55. own['idlecampos_x'] = 0
  56. own['speed_mult'] = 1.00
  57. controlcube['driving'] = False
  58. acam = scene.active_camera
  59. focallength = dict['focal_length']
  60. cam1.lens = focallength
  61. cam2.lens = focallength
  62. cam3.lens = focallength
  63. #if 1 == 1:
  64. #if own['playback'] == False:
  65. if controlcube['driving'] == False:
  66. if down.triggered == True and LAST_GRIND == False and walk == 0:
  67. hitPosition = down.hitPosition
  68. distance = own.getDistanceTo(hitPosition)
  69. cam_moved = 1
  70. if distance < .2:
  71. camempty['hitdown'] = True
  72. cam.height = cam_height + .3
  73. cam.damping = .0
  74. #print("raise cam")
  75. if zdist < -.2:
  76. cam.height = lastCamheight + .01
  77. cam.damping = .0
  78. raised = 1
  79. if (distance > .4 and distance < .6) and zdist > -.2 and raised == 0:
  80. camheight2 = cam.height - .001
  81. if cam.height < .2:
  82. cam.height = camheight2
  83. #print("slow lower")
  84. if distance >= .6 and zdist > -.2 and raised == 0:
  85. cam.height = cam.height - .02
  86. #print("slow lower2")
  87. if down.triggered == False and LAST_GRIND == False and cam_moved == 0 and walk == 0:
  88. camempty['hitdown'] = False
  89. if cam_height > (cam_def_height + .06) and zdist > -.2 and raised == 0:
  90. cam.height = cam_height - .02
  91. if cam_height < -.6 and cam_moved == 0 and LAST_GRIND == False and zdist > -.2 and raised == 0 and walk == 0:
  92. cam_height = .1
  93. if LAST_GRIND == True and walk == 0:
  94. if cam.height < -.5 or zdist < -.2:
  95. cam.height = cam.height + .013
  96. if cam.height >= -.5 and not down.triggered:
  97. pass
  98. if walk == 1:
  99. if dropinCol.positive == True and lasty == True:
  100. pass
  101. else:
  102. pass
  103. controlcube['lastCamheight'] = cam.height
  104. #########
  105. cam.min = dict['cam_min']
  106. cam.max = dict['cam_max']
  107. cont.activate(own.actuators['Camera'])
  108. ########
  109. if near.triggered == True and walk == 0:
  110. #print("near")
  111. if cam.min < 1:
  112. cam.min = cam.min + .1
  113. cam.max = cam.max + .1
  114. cam.height = cam_height + .01
  115. cam.damping = .001
  116. cont.activate(move)
  117. else:
  118. #print("far")
  119. cont.deactivate(move)
  120. if cam.min > cam_def_min:
  121. cam.min = cam.min - .05
  122. cam.max = cam.max - .05
  123. cam.damping = .0
  124. if cam.damping != 0 and down.triggered == False and near.triggered == False:
  125. cam.damping = 0.91
  126. obj = cont.owner
  127. cube = controlcube
  128. to = cube
  129. from2 = obj
  130. distance = 0.0
  131. property = ""
  132. face = 1
  133. xray = 0
  134. poly = 0
  135. hit = obj.rayCast( to, from2, distance, property, face, xray, poly)
  136. control = "control_cube.002"
  137. hitobj = hit[0]
  138. hitobj = str(hitobj)
  139. if hitobj != control and walk == 0:
  140. cam.damping = .0
  141. if cam.height < 3:
  142. cam.height = cam_height + .1
  143. if dict['menu_idle_timer'] > 300:
  144. move_len = 2048
  145. if own['idlecampos_x'] < move_len:
  146. own['idlecampos_x'] += 1
  147. if own['idlecampos_x'] == move_len:
  148. own['idlecampos_x'] = 0
  149. if own['idlecampos_x'] < (move_len / 2):
  150. move = [.0001, 0, 0]
  151. freecam.applyMovement( move, True)
  152. freecam.applyRotation([.0001, 0, .0001],True)
  153. if own['idlecampos_x'] > (move_len / 2):
  154. move = [-.0001, 0, 0]
  155. freecam.applyMovement( move, True)
  156. freecam.applyRotation([-.0001, 0, -.0001],True)
  157. if dict['npause'] == True:
  158. cont.deactivate(own.actuators['Camera'])
  159. controlcube['camera'] = 2
  160. if controlcube['camera'] == 2 and dict['joy_con'] == 1:
  161. cont.deactivate(own.actuators['Camera'])
  162. scene.active_camera = freecam
  163. cont.activate(cube.actuators['freecam'])
  164. #print('activating camera', freecam)
  165. #####
  166. #get value 0-100
  167. lLR = dict['lLR'] / .082 * 100
  168. lUD = dict['lUD'] / .082 * 100 - 20 / 80
  169. rLR = dict['rLR'] / .082 * 100 - 20 / 80
  170. rUD = dict['rUD'] / .082 * 100 - 20 / 80
  171. lTrig = dict['lTrig'] / .082 * 100 - 20 / 80
  172. rTrig = dict['rTrig'] / .082 * 100 - 20 / 80
  173. # lBump = dict['lBump']
  174. # rBump = dict['rBump']
  175. if lLR < -20:
  176. lmLR = round((lLR + 20) / 80 * 100, 0)
  177. elif lLR > 20:
  178. lmLR = round((lLR - 20) / 80 * 100, 0)
  179. else: lmLR = 0
  180. if lUD > 20:
  181. lmUD = round((lUD - 20) / 80 * 100, 0)
  182. elif lUD < -20:
  183. lmUD = round((lUD + 20) / 80 * 100, 0)
  184. else: lmUD = 0
  185. if rLR < -20:
  186. rmLR = round((rLR + 20) / 80 * 100, 0)
  187. elif rLR > 20:
  188. rmLR = round((rLR - 20) / 80 * 100, 0)
  189. else: rmLR = 0
  190. if rUD > 20:
  191. rmUD = round((rUD - 20) / 80 * 100, 0)
  192. elif rUD < -20:
  193. rmUD = round((rUD + 20) / 80 * 100, 0)
  194. else: rmUD = 0
  195. if lTrig > 3:
  196. mTrig = lTrig * -1
  197. elif rTrig > 3:
  198. mTrig = rTrig
  199. else: mTrig = 0
  200. #move camera
  201. damping = .95
  202. damping2 = 1.005
  203. mult = .0005 * own['speed_mult']
  204. move_x = lmUD * mult
  205. move_y = lmLR * mult
  206. move_z = (mTrig * -mult) / 2#4
  207. rot_mult = -.00015 * own['speed_mult']
  208. rot_x = rmUD * rot_mult
  209. rot_y = rmLR * rot_mult
  210. if move_x == 0 and own['last_move_x'] != 0:
  211. move_x = own['last_move_x'] * damping
  212. if move_y == 0 and own['last_move_y'] != 0:
  213. move_y = own['last_move_y'] * damping
  214. if move_z == 0 and own['last_move_z'] != 0:
  215. move_z = own['last_move_z'] * damping
  216. if rot_x == 0 and own['last_rot_x'] != 0:
  217. rot_x = own['last_rot_x'] * damping
  218. if rot_y == 0 and own['last_rot_y'] != 0:
  219. rot_y = own['last_rot_y'] * damping
  220. move = [move_y, 0, move_x]
  221. freecam.applyMovement( move, True)
  222. freecam.applyMovement([0, 0, move_z], False)
  223. freecam.applyRotation([rot_x, 0, 0],True)
  224. freecam.applyRotation([0, 0, rot_y],False)
  225. # mult = .1 #* own['speed_mult']
  226. # if lBump == True and own['lBump'] == False:
  227. # if own['speed_mult'] > .1:
  228. # own['speed_mult'] = round(own['speed_mult'] - mult, 2)
  229. # if rBump == True and own['rBump'] == False:
  230. # if own['speed_mult'] < 5.5:
  231. # own['speed_mult'] = round(own['speed_mult'] + mult, 2)
  232. ################
  233. #print(dict['walk'], 'walk')
  234. multer = .02
  235. if dict['walk'] == 1:
  236. if dict['cur_ccH_targetHeight'] < .8:
  237. dist = .8 - dict['cur_ccH_targetHeight']
  238. dict['cur_ccH_targetHeight'] = dict['cur_ccH_targetHeight'] + (dist * multer)
  239. if dict['cur_ccH_targetHeight'] > .799:
  240. dict['cur_ccH_targetHeight'] = .8
  241. #ccH_targetHeight = .9
  242. else:
  243. if dict['cur_ccH_targetHeight'] < dict['cch_targetHeight']:
  244. dist = dict['cur_ccH_targetHeight'] - dict['cch_targetHeight']
  245. dict['cur_ccH_targetHeight'] = dict['cur_ccH_targetHeight'] - (dist * multer)
  246. if dict['cur_ccH_targetHeight'] > dict['cch_targetHeight'] - .001:
  247. dict['cur_ccH_targetHeight'] = dict['cch_targetHeight']
  248. if dict['cur_ccH_targetHeight'] > dict['cch_targetHeight']:
  249. dist = dict['cch_targetHeight'] - dict['cur_ccH_targetHeight']
  250. dict['cur_ccH_targetHeight'] = dict['cur_ccH_targetHeight'] + (dist * multer)
  251. if dict['cur_ccH_targetHeight'] < dict['cch_targetHeight'] + .001:
  252. dict['cur_ccH_targetHeight'] = dict['cch_targetHeight']
  253. ccH_targetHeight = dict['cur_ccH_targetHeight']
  254. #print(dict['cur_ccH_targetHeight'])
  255. #dict['cur_ccH_targetHeight'] =
  256. #ccH_targetHeight = .3
  257. ccH = camCube.worldPosition.z
  258. pH = camCube.parent.worldPosition.z
  259. ccheight = (round((ccH - pH), 2) - .4)
  260. #print(ccheight, 'camera target height')
  261. localPos = camCube.localPosition.z
  262. #print(localPos, 'local position')
  263. if localPos != ccH_targetHeight:
  264. num = ccH_targetHeight - localPos
  265. camCube.localPosition.z += num
  266. #if camHeightSet not in own:
  267. if 1 == 1:
  268. #if ccheight != ccH_targetHeight:
  269. num = ccH_targetHeight - ccheight
  270. #camCube.worldPosition.x = controlcube.worldPosition.x
  271. #camCube.worldPosition.y = controlcube.worldPosition.y
  272. #camCube.worldPosition.z = controlcube.worldPosition.z + num
  273. else:
  274. own['camHeightSet'] = True
  275. if dict['npause'] == False:
  276. cont.activate(own.actuators['Camera'])
  277. controlcube['camera'] = 0
  278. main()