123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- #zskcam
- import bge
- import mathutils
- from mathutils import *
- scene = bge.logic.getCurrentScene()
- cont = bge.logic.getCurrentController()
- own = cont.owner
- def main():
- dict = bge.logic.globalDict
- camempty = scene.objects['camEmpty.001']
- controlcube = scene.objects['control_cube.002']
-
- camCube = scene.objects['camCube']
-
- dropinCol = controlcube.sensors['dropinCol']
- LAST_GRIND = controlcube['LAST_GRIND']
- up = cont.sensors['up']
- ray = cont.sensors['up']
- down = cont.sensors['down']
- left = cont.sensors['left']
- right = cont.sensors['right']
- distance = 0.12
- cam = cont.actuators["Camera"]
- near = cont.sensors["Near"]
- move = own.actuators["move"]
- #match camera actuaotor
- cam_def_height = dict['cam_height'] #-.1 #-.6
- #cam_def_min = 1.6
- #cam_def_max = 2.4
- cam_def_min = dict['cam_min']
- cam_def_max = dict['cam_max']
- cam_height = cam.height
- cam_min = cam.min
- cam_max = cam.max
- lasty = controlcube['lasty']
- cam_moved = 0
- lastCamheight = controlcube['lastCamheight']
- raised = 0
- walk = controlcube['walk']
- cam.axis = 4
- ccheight = controlcube.worldPosition[2]
- camwpz = own.worldPosition[2]
- zdist = camwpz - ccheight
-
- cam1 = scene.objects['Camera.003']
- cam2 = scene.objects['freecam']
- cam3 = scene.objects['followcam']
-
- camList = scene.cameras
- freecam = camList["freecam"]
-
- if 'init' not in own:
- own['init'] = 1
- own['last_move_x'] = 0
- own['last_move_y'] = 0
- own['last_move_z'] = 0
- own['last_rot_x'] = 0
- own['last_rot_y'] = 0
- own['last_rot_z'] = 0
- own['idlecampos_x'] = 0
- own['speed_mult'] = 1.00
- controlcube['driving'] = False
- acam = scene.active_camera
- focallength = dict['focal_length']
- cam1.lens = focallength
- cam2.lens = focallength
- cam3.lens = focallength
-
-
- #if 1 == 1:
- #if own['playback'] == False:
- if controlcube['driving'] == False:
- if down.triggered == True and LAST_GRIND == False and walk == 0:
- hitPosition = down.hitPosition
- distance = own.getDistanceTo(hitPosition)
- cam_moved = 1
- if distance < .2:
- camempty['hitdown'] = True
- cam.height = cam_height + .3
- cam.damping = .0
- #print("raise cam")
- if zdist < -.2:
- cam.height = lastCamheight + .01
- cam.damping = .0
- raised = 1
- if (distance > .4 and distance < .6) and zdist > -.2 and raised == 0:
- camheight2 = cam.height - .001
- if cam.height < .2:
- cam.height = camheight2
- #print("slow lower")
- if distance >= .6 and zdist > -.2 and raised == 0:
- cam.height = cam.height - .02
- #print("slow lower2")
- if down.triggered == False and LAST_GRIND == False and cam_moved == 0 and walk == 0:
- camempty['hitdown'] = False
- if cam_height > (cam_def_height + .06) and zdist > -.2 and raised == 0:
- cam.height = cam_height - .02
- if cam_height < -.6 and cam_moved == 0 and LAST_GRIND == False and zdist > -.2 and raised == 0 and walk == 0:
- cam_height = .1
- if LAST_GRIND == True and walk == 0:
- if cam.height < -.5 or zdist < -.2:
- cam.height = cam.height + .013
- if cam.height >= -.5 and not down.triggered:
- pass
-
- if walk == 1:
- if dropinCol.positive == True and lasty == True:
- pass
- else:
- pass
- controlcube['lastCamheight'] = cam.height
- #########
- cam.min = dict['cam_min']
- cam.max = dict['cam_max']
- cont.activate(own.actuators['Camera'])
- ########
-
- if near.triggered == True and walk == 0:
- #print("near")
- if cam.min < 1:
- cam.min = cam.min + .1
- cam.max = cam.max + .1
- cam.height = cam_height + .01
- cam.damping = .001
- cont.activate(move)
-
- else:
- #print("far")
- cont.deactivate(move)
- if cam.min > cam_def_min:
- cam.min = cam.min - .05
- cam.max = cam.max - .05
- cam.damping = .0
- if cam.damping != 0 and down.triggered == False and near.triggered == False:
- cam.damping = 0.91
-
- obj = cont.owner
- cube = controlcube
- to = cube
- from2 = obj
- distance = 0.0
- property = ""
- face = 1
- xray = 0
- poly = 0
- hit = obj.rayCast( to, from2, distance, property, face, xray, poly)
- control = "control_cube.002"
- hitobj = hit[0]
- hitobj = str(hitobj)
- if hitobj != control and walk == 0:
- cam.damping = .0
- if cam.height < 3:
- cam.height = cam_height + .1
-
- if dict['menu_idle_timer'] > 300:
- move_len = 2048
- if own['idlecampos_x'] < move_len:
- own['idlecampos_x'] += 1
- if own['idlecampos_x'] == move_len:
- own['idlecampos_x'] = 0
-
- if own['idlecampos_x'] < (move_len / 2):
- move = [.0001, 0, 0]
- freecam.applyMovement( move, True)
- freecam.applyRotation([.0001, 0, .0001],True)
- if own['idlecampos_x'] > (move_len / 2):
- move = [-.0001, 0, 0]
- freecam.applyMovement( move, True)
- freecam.applyRotation([-.0001, 0, -.0001],True)
-
- if dict['npause'] == True:
- cont.deactivate(own.actuators['Camera'])
- controlcube['camera'] = 2
- if controlcube['camera'] == 2 and dict['joy_con'] == 1:
- cont.deactivate(own.actuators['Camera'])
- scene.active_camera = freecam
- cont.activate(cube.actuators['freecam'])
- #print('activating camera', freecam)
- #####
- #get value 0-100
- lLR = dict['lLR'] / .082 * 100
- lUD = dict['lUD'] / .082 * 100 - 20 / 80
- rLR = dict['rLR'] / .082 * 100 - 20 / 80
- rUD = dict['rUD'] / .082 * 100 - 20 / 80
- lTrig = dict['lTrig'] / .082 * 100 - 20 / 80
- rTrig = dict['rTrig'] / .082 * 100 - 20 / 80
- # lBump = dict['lBump']
- # rBump = dict['rBump']
-
- if lLR < -20:
- lmLR = round((lLR + 20) / 80 * 100, 0)
- elif lLR > 20:
- lmLR = round((lLR - 20) / 80 * 100, 0)
- else: lmLR = 0
-
- if lUD > 20:
- lmUD = round((lUD - 20) / 80 * 100, 0)
- elif lUD < -20:
- lmUD = round((lUD + 20) / 80 * 100, 0)
- else: lmUD = 0
-
- if rLR < -20:
- rmLR = round((rLR + 20) / 80 * 100, 0)
- elif rLR > 20:
- rmLR = round((rLR - 20) / 80 * 100, 0)
- else: rmLR = 0
-
- if rUD > 20:
- rmUD = round((rUD - 20) / 80 * 100, 0)
- elif rUD < -20:
- rmUD = round((rUD + 20) / 80 * 100, 0)
- else: rmUD = 0
-
- if lTrig > 3:
- mTrig = lTrig * -1
- elif rTrig > 3:
- mTrig = rTrig
- else: mTrig = 0
-
- #move camera
- damping = .95
- damping2 = 1.005
- mult = .0005 * own['speed_mult']
- move_x = lmUD * mult
- move_y = lmLR * mult
- move_z = (mTrig * -mult) / 2#4
-
- rot_mult = -.00015 * own['speed_mult']
- rot_x = rmUD * rot_mult
- rot_y = rmLR * rot_mult
-
- if move_x == 0 and own['last_move_x'] != 0:
- move_x = own['last_move_x'] * damping
- if move_y == 0 and own['last_move_y'] != 0:
- move_y = own['last_move_y'] * damping
- if move_z == 0 and own['last_move_z'] != 0:
- move_z = own['last_move_z'] * damping
- if rot_x == 0 and own['last_rot_x'] != 0:
- rot_x = own['last_rot_x'] * damping
- if rot_y == 0 and own['last_rot_y'] != 0:
- rot_y = own['last_rot_y'] * damping
-
-
- move = [move_y, 0, move_x]
- freecam.applyMovement( move, True)
- freecam.applyMovement([0, 0, move_z], False)
- freecam.applyRotation([rot_x, 0, 0],True)
- freecam.applyRotation([0, 0, rot_y],False)
-
- # mult = .1 #* own['speed_mult']
- # if lBump == True and own['lBump'] == False:
- # if own['speed_mult'] > .1:
- # own['speed_mult'] = round(own['speed_mult'] - mult, 2)
- # if rBump == True and own['rBump'] == False:
- # if own['speed_mult'] < 5.5:
- # own['speed_mult'] = round(own['speed_mult'] + mult, 2)
-
-
-
- ################
- #print(dict['walk'], 'walk')
- multer = .02
- if dict['walk'] == 1:
- if dict['cur_ccH_targetHeight'] < .8:
- dist = .8 - dict['cur_ccH_targetHeight']
-
- dict['cur_ccH_targetHeight'] = dict['cur_ccH_targetHeight'] + (dist * multer)
- if dict['cur_ccH_targetHeight'] > .799:
- dict['cur_ccH_targetHeight'] = .8
- #ccH_targetHeight = .9
- else:
-
- if dict['cur_ccH_targetHeight'] < dict['cch_targetHeight']:
- dist = dict['cur_ccH_targetHeight'] - dict['cch_targetHeight']
- dict['cur_ccH_targetHeight'] = dict['cur_ccH_targetHeight'] - (dist * multer)
- if dict['cur_ccH_targetHeight'] > dict['cch_targetHeight'] - .001:
- dict['cur_ccH_targetHeight'] = dict['cch_targetHeight']
-
- if dict['cur_ccH_targetHeight'] > dict['cch_targetHeight']:
- dist = dict['cch_targetHeight'] - dict['cur_ccH_targetHeight']
- dict['cur_ccH_targetHeight'] = dict['cur_ccH_targetHeight'] + (dist * multer)
- if dict['cur_ccH_targetHeight'] < dict['cch_targetHeight'] + .001:
- dict['cur_ccH_targetHeight'] = dict['cch_targetHeight']
-
-
- ccH_targetHeight = dict['cur_ccH_targetHeight']
- #print(dict['cur_ccH_targetHeight'])
- #dict['cur_ccH_targetHeight'] =
- #ccH_targetHeight = .3
- ccH = camCube.worldPosition.z
- pH = camCube.parent.worldPosition.z
- ccheight = (round((ccH - pH), 2) - .4)
- #print(ccheight, 'camera target height')
-
- localPos = camCube.localPosition.z
- #print(localPos, 'local position')
- if localPos != ccH_targetHeight:
- num = ccH_targetHeight - localPos
- camCube.localPosition.z += num
- #if camHeightSet not in own:
- if 1 == 1:
- #if ccheight != ccH_targetHeight:
- num = ccH_targetHeight - ccheight
- #camCube.worldPosition.x = controlcube.worldPosition.x
- #camCube.worldPosition.y = controlcube.worldPosition.y
- #camCube.worldPosition.z = controlcube.worldPosition.z + num
- else:
- own['camHeightSet'] = True
-
- if dict['npause'] == False:
- cont.activate(own.actuators['Camera'])
- controlcube['camera'] = 0
- main()
|