123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- #zskcam
- import bge
- import mathutils
- from mathutils import *
- scene = bge.logic.getCurrentScene()
- import camFSM
-
- def main(cont):
- #camFSM.main(cont)
- own = cont.owner
- 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"]
- cam_def_height = dict['cam_height']
- 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
- dict['cur_ccH_min'] = dict['cam_walk_min']
- dict['cur_ccH_max'] = dict['cam_walk_max']
- cam.height = dict['cam_height']
- dict['cam_state'] = 'walking'
- controlcube['ragdoll_active'] = False
- dict['camera'] = cam1
- acam = scene.active_camera
-
- def get_cam_state():
- if dict['npause']:
- if dict['menu_idle_timer'] > 300:
- #dict['cam_state'] = 'pause_idle'
- dict['cam_state'] = 'PauseIdleCam'
- else:
- dict['cam_state'] = 'PauseCam'
- elif walk == 1:
- if controlcube['ragdoll_active']:
- dict['cam_state'] = 'RagdollCam'
- else:
- dict['cam_state'] = 'WalkCam'
- elif controlcube['driving']:
- dict['cam_state'] = 'driving'
- else:
- dict['cam_state'] = 'RollCam'
- #print(dict['cam_state'])
-
-
- if controlcube['driving'] == False:
- LAST_GRIND = False
- if down.triggered == True and LAST_GRIND == False and walk == 0:
- hitPosition = down.hitPosition
- distance = own.getDistanceTo(hitPosition)
- cam_moved = 1
-
- if down.triggered == False and LAST_GRIND == False and cam_moved == 0 and walk == 0:
- camempty['hitdown'] = False
- if cam_height > (cam_def_height + .08) and zdist > -.2 and raised == 0:
- cam.height = cam_height - .02
- #print('raising a')
- if cam_height < -.6 and cam_moved == 0 and LAST_GRIND == False and zdist > -.2 and raised == 0 and walk == 0:
- cam_height = .1
- #print('raising b')
- if LAST_GRIND == True and walk == 0:
- if cam.height < -.5 or zdist < -.2:
- cam.height = cam.height + .013
- #print('raising c')
- if cam.height >= -.5 and not down.triggered:
- pass
-
- controlcube['lastCamheight'] = cam.height
- #activating######
- 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
- print('moving cam up')
- 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
- to2 = to.worldPosition
- pos = [to.worldPosition.x, to.worldPosition.y, to.worldPosition.z]
- pos[2] = pos[2] - .2
- from2 = obj
- from3 = [from2.worldPosition.x, from2.worldPosition.y, from2.worldPosition.z]
- from3[2] = from3[2] - .2
- distance = 0.0
- property = ""
- face = 1
- xray = 0
- poly = 0
- hit = obj.rayCast( pos, from3, distance, property, face, xray, poly)
- control = "control_cube.002"
- hitobj = hit[0]
- hitobj = str(hitobj)
-
- if hit[0]:
- #if hitobj != control and walk == 0 and 'vert' not in hit[0] and 'ground' in hit[0] and controlcube['ragdoll_active'] == False:
- if hitobj != control and walk == 0 and 'vert' not in hit[0] and 'ground' in hit[0]:
- cam.damping = .01
- if cam.height < 2:
- cam.height = cam_height + .1
- cam.max = cam.max - .2
- print('small move', cam.height, dict['cam_height'])
- elif cam.height >= 2 and cam.height < 4:
- cam.height = cam_height + .05
- cam.max = cam.max - .05
- print('big move')
-
- 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'])
- 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
-
- 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)
-
-
- ################
- multer = .02
- if dict['walk'] == 1 and not controlcube['ragdoll_active']:
- if dict['cur_ccH_targetHeight'] < dict['cam_walk_height']:
- dist = dict['cam_walk_height'] - dict['cur_ccH_targetHeight']
-
- dict['cur_ccH_targetHeight'] = dict['cur_ccH_targetHeight'] + (dist * multer)
- if dict['cur_ccH_targetHeight'] > dict['cam_walk_height']:
- dict['cur_ccH_targetHeight'] = dict['cam_walk_height']
-
- cam.min = dict['cam_walk_min']
- cam.max = dict['cam_walk_max']
-
- 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']
-
- ccH = camCube.worldPosition.z
- pH = camCube.parent.worldPosition.z
- ccheight = (round((ccH - pH), 2) - .4)
-
- localPos = camCube.localPosition.z
- if localPos != ccH_targetHeight:
- num = ccH_targetHeight - localPos
- camCube.localPosition.z += num
- #if camHeightSet not in own:
- #if 1 == 1:
- num = ccH_targetHeight - ccheight
- #else:
- #own['camHeightSet'] = True
- try:
- if dict['npause'] == False and controlcube['ragdoll_active'] == False:
- cont.activate(own.actuators['Camera'])
- controlcube['camera'] = 0
- if controlcube['ragdoll_active'] == True:
- #print('ragdoll_camera', own.actuators['Camera'].object)
- own.actuators['Camera'].object = scene.objects['ragdoll_parent']
- cont.activate(own.actuators['Camera'])
- controlcube['camera'] = 0
- except:
- pass
-
- def set_lens_dist():
- cur_lens = cam1.lens
- cur_min = cam.min
- cur_max = cam.max
- inc = .025
- if walk == 1:
- #lens
- if dict['walk_focal_length'] > cur_lens:
- new_lens = cur_lens + inc
- else:
- new_lens = cur_lens - inc
- if cur_lens > (dict['walk_focal_length'] - .1) and cur_lens < (dict['walk_focal_length'] + .1):
- new_lens = dict['walk_focal_length']
-
- #distance
- inc = .025
- if cur_min > (dict['cam_walk_min'] - inc):
- new_min = cur_min - inc
- if cur_min < (dict['cam_walk_min'] + inc):
- new_min = cur_min + inc
- if cur_max > (dict['cam_walk_max'] - inc):
- new_max = cur_min - inc
- if cur_max < (dict['cam_walk_max'] + inc):
- new_max = cur_min + inc
- else:
- #lens
- if dict['focal_length'] > cur_lens:
- new_lens = cur_lens + inc
- else:
- new_lens = cur_lens - inc
- if cur_lens > (dict['focal_length'] - .1) and cur_lens < (dict['focal_length'] + .1):
- new_lens = dict['focal_length']
-
- #distance
- inc = .025
- if cur_min > (dict['cam_min'] - inc):
- new_min = cur_min - inc
- if cur_min < (dict['cam_min'] + inc):
- new_min = cur_min + inc
- if cur_max > (dict['cam_max'] - inc):
- new_max = cur_min - inc
- if cur_max < (dict['cam_max'] + inc):
- new_max = cur_min + inc
-
- focallength = new_lens
- cam1.lens = focallength
- cam2.lens = focallength
- cam3.lens = focallength
- try:
- cam.min = new_min
- cam.max = new_max
- except:
- pass
- set_lens_dist()
- get_cam_state()
- camFSM.main(cont)
|