Zero_g - object motion relative to another

zero_g.blend (575.5 KB)

import bge, mathutils
from mathutils import Vector
def update():
    scene = bge.logic.getSceneList()['Scene']
    player = scene.objects['Player']
    player.worldPosition = player['ship'][0].worldTransform @ player['ship'][1]
    player.worldOrientation =  player['ship'][0].worldOrientation @ player['ship'][2]
    player.worldPosition += player.worldOrientation @ Vector([player['x'],player['y'],player['z']])
def main():

    cont = bge.logic.getCurrentController()
    own = cont.owner
    ship = own.scene.objects['Ship']
    #print('test')
    if 'callback' not in own:
        own.scene.pre_draw.append(update)
        own['callback']=True
    if cont.sensors['W'].positive and own['x']<=.09:
        own['x']+=.01
    elif cont.sensors['S'].positive and own['x']>=-.09:
        own['x']-=.01
            
    else:
        own['x']*=.925  
    if cont.sensors['A'].positive:
        own.applyRotation((0,0,.01),1)
    elif cont.sensors['D'].positive:
        own.applyRotation((0,0,-.01),1)
                  
    ray = cont.sensors['Ray']
    if ray.positive:
        if own['z']<0:
            own['z']=0
        if cont.sensors['Space'].positive:
            own['z']=.2    
    else:
        if own['z']>=-.9:
            own['z']-=.01        
            
    own['ship']= ( ship, ship.worldTransform.inverted() @ own.worldPosition , ship.worldOrientation.inverted() @ own.worldOrientation  )  
        
main()
always-----python
W----------/
S----------/
A---------/
D--------/
Space-/
1 Like