Physics Cam 4.0 Gravi_Cam


import bge




def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner
    CTRL = cont.sensors['CTRL']
    if 'ZHome' not in own:
        for objects in bge.logic.getCurrentScene().objects:
            if 'ZoomHome' in objects:
                own['ZHome']=objects
                print('FoundZoom')
            if 'CameraHome' in objects:
                print('FoundHome')
                
                own['CamHome']=objects
            if 'PlayerProp' in objects:
                own['Player']=objects
                print('FoundPlayer')
    else:
        own.applyForce((0,0,9.8*own.mass),0)
        Ray = own.rayCast(own['Player'].worldPosition,own.worldPosition,0,'',0,0,0)
        bge.render.drawLine(own['Player'].worldPosition,own.worldPosition,(1,0,0))
        
        if Ray[0]:
            ##print(Ray[0])
            if Ray[0]!=own['Player']:
                if own['Zoom']<=9:
                    own['Zoom']+=1
            else:        
                if own['Zoom']>=1:
                    own['Zoom']-=1      
        else:
            
            if own['Zoom']>=1:
                own['Zoom']-=1                       
        V=[]
        if not CTRL.positive and own['Zoom']<10:
            if Ray[0] or Ray[0]==Player:
                V=[]
                
                if Ray[0]:
                    if Ray[0]!=own['Player']:
                        own.worldPosition=Ray[1]+(own.worldOrientation.col[2]*-.1)
                        own.worldLinearVelocity*=0
                    else:
                        V = own.getVectTo(own['CamHome'])
                            
                else:        
                    V = own.getVectTo(own['CamHome'])
                own.alignAxisToVect(own['CamHome'].worldOrientation.col[2],2,.1)
                own.alignAxisToVect(own['CamHome'].worldOrientation.col[1],1,.1)
            
        if CTRL.positive or own['Zoom']==10:
            
                ##print('Zoom2')
                
                V = own.getVectTo(own['ZHome'])
                own.alignAxisToVect(own['ZHome'].worldOrientation.col[2],2,.1)
                own.alignAxisToVect(own['ZHome'].worldOrientation.col[1],1,.1)
                 
        own.applyForce(V[1]*V[0]*(300-(own['Zoom']*30)),0)
        own.worldLinearVelocity*=.00125
        
        
main()



Dependencies
1.property - ‘CameraHome’ in Standard cam position Oriented the way the camera faces in position- No collision, _empty - parented to player

2.Property - ‘ZoomHome’ in Zoom position object , Oriented the way the camera faces in position-
_parented to player

3.Camera Root - object running script

Always-------python
CTRL---------/

4 ->CTRL = keyboard sensor positive mode , Zoom key

5.Camera = slow parented to CameraRoot

6.a Player marked with the property ‘Player

Demo file
Space = place obstruction
left control = Zoom in

Attachments

GraviCam (2).blend (516 KB)

Bug 1 = no filter on apply force for when V!= a vector

added code

if len(V)!=0

this would work as well:
if V!=[]


import bge




def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner
    CTRL = cont.sensors['CTRL']
    if 'ZHome' not in own:
        for objects in bge.logic.getCurrentScene().objects:
            if 'ZoomHome' in objects:
                own['ZHome']=objects
                print('FoundZoom')
            if 'CameraHome' in objects:
                print('FoundHome')
                
                own['CamHome']=objects
            if 'PlayerProp' in objects:
                own['Player']=objects
                print('FoundPlayer')
    else:
        own.applyForce((0,0,9.8*own.mass),0)
        Ray = own.rayCast(own['Player'].worldPosition,own.worldPosition,0,'',0,0,0)
        bge.render.drawLine(own['Player'].worldPosition,own.worldPosition,(1,0,0))
        
        if Ray[0]:
            ##print(Ray[0])
            if Ray[0]!=own['Player']:
                if own['Zoom']<=9:
                    own['Zoom']+=1
            else:        
                if own['Zoom']>=1:
                    own['Zoom']-=1      
        else:
            
            if own['Zoom']>=1:
                own['Zoom']-=1                       
        V=[]
        if not CTRL.positive and own['Zoom']<10:
            if Ray[0] or Ray[0]==Player:
                V=[]
                
                if Ray[0]:
                    if Ray[0]!=own['Player']:
                        own.worldPosition=Ray[1]+(own.worldOrientation.col[2]*-.1)
                        own.worldLinearVelocity*=0
                    else:
                        V = own.getVectTo(own['CamHome'])
                            
                else:        
                    V = own.getVectTo(own['CamHome'])
                own.alignAxisToVect(own['CamHome'].worldOrientation.col[2],2,.1)
                own.alignAxisToVect(own['CamHome'].worldOrientation.col[1],1,.1)
            
        if CTRL.positive or own['Zoom']==10:
            
                ##print('Zoom2')
                
                V = own.getVectTo(own['ZHome'])
                own.alignAxisToVect(own['ZHome'].worldOrientation.col[2],2,.1)
                own.alignAxisToVect(own['ZHome'].worldOrientation.col[1],1,.1)
<b>        if len(V)&gt;0:         </b>
            own.applyForce(V[1]*V[0]*(300-(own['Zoom']*30)),0)
            own.worldLinearVelocity*=.00125
        
        
main()



This looks useful. Raycast always gives good results for most of stuff. I hope to use this for Von Der Dead.