pop missiles
missile.blend (687.5 KB)
import bge
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
if not own.parent and not cont.sensors['Ray'].positive:
if 'target' not in own:
own['target'] = own.scene.objects['a_target']
target = own['target']
#own.applyForce((0,0,9.8*own.mass),0)
local = own.worldTransform.inverted() @ target.worldPosition
#print(local)
own.worldAngularVelocity*=.9
if local.x>0:
#target is in front
if local.y>.25:
own.applyTorque((0,0,6),1)
own.localLinearVelocity.x*=.975
if local.y>.5:
own.applyTorque((0,0,6),1)
elif local.y<-.25:
own.applyTorque((0,0,-6),1)
own.localLinearVelocity.x*=.975
if local.y>.5:
own.applyTorque((0,0,-6),1)
else:
own.localAngularVelocity.z*=.975
if local.z>.25:
own.applyTorque((0,-6,0),1)
own.localLinearVelocity.x*=.975
if local.z>.5:
own.applyTorque((0,-6,0),1)
elif local.z<-.25:
own.applyTorque((0,6,0),1)
own.localLinearVelocity.x*=.975
if local.z<-.5:
own.applyTorque((0,6,0),1)
else:
own.localAngularVelocity.y*=.95
if abs(local.y)-local.x<0 and abs(local.z)-local.x<0:
#missile aimed at target
own.localAngularVelocity.y*=.95
own.localAngularVelocity.z*=.95
own.applyForce((125,0,0),1)
own.alignAxisToVect(own.getVectTo(target)[1],0,.25)
own.applyForce((0,0,9.8),0)
own.localLinearVelocity.z*=.95
own.localLinearVelocity.y*=.95
else:
if local.y>.1:
own.applyTorque((0,0,6),1)
if local.y>.5:
own.applyTorque((0,0,6),1)
elif local.y<.1:
own.applyTorque((0,0,-6),1)
if local.y<-.5:
own.applyTorque((0,0,-6),1)
if local.z>.1:
own.applyTorque((0,-6,0),1)
if local.z>.5:
own.applyTorque((0,-6,0),1)
elif local.z<.1:
own.applyTorque((0,6,0),1)
if local.z<-.5:
own.applyTorque((0,6,0),1)
elif cont.sensors['Ray'].positive and not own.parent:
print('fire')
own.setParent(cont.sensors['Ray'].hitObject,0,1)
own.worldPosition = cont.sensors['Ray'].hitPosition
main()