Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bge, Util, math
- cont = bge.logic.getCurrentController()
- scene = bge.logic.getCurrentScene()
- own = cont.owner
- keySens = cont.sensors["ReadInput"]
- ori = Util.getRotInDegrees(own)
- own['alt'] = own.worldPosition[2]
- if own["sim_flightmode"] == False: #We are in basic mode
- if [bge.events.LEFTARROWKEY, bge.logic.KX_INPUT_ACTIVE] in keySens.events:
- #ori = Util.getRotInDegrees(own)
- #ori[2] += own["yawRate"]
- #Util.setRotInDegrees(ori, own, False)
- own.applyTorque([0, 0, own['yawRate']])
- elif [bge.events.RIGHTARROWKEY, bge.logic.KX_INPUT_ACTIVE] in keySens.events:
- #ori = Util.getRotInDegrees(own)
- #ori[2] -= own["yawRate"]
- #Util.setRotInDegrees(ori, own, False)
- own.applyTorque([0, 0, -own['yawRate']])
- if [bge.events.UPARROWKEY, bge.logic.KX_INPUT_ACTIVE] in keySens.events:
- #ori = Util.getRotInDegrees(own)
- #ori[0] -= own["pitchRate"]
- own.applyTorque([-own['pitchRate'], 0, 0], True)
- if ori[0] < -(own["maxPitch"]):
- ori[0] = -(own["maxPitch"])
- Util.setRotInDegrees(ori, own)
- elif [bge.events.DOWNARROWKEY, bge.logic.KX_INPUT_ACTIVE] in keySens.events:
- #ori = Util.getRotInDegrees(own)
- #ori[0] += own["pitchRate"]
- own.applyTorque([own['pitchRate'], 0, 0], True)
- if ori[0] > (own["maxPitch"]):
- ori[0] = (own["maxPitch"])
- Util.setRotInDegrees(ori, own)
- if len(keySens.events) == 0 or (len(keySens.events) == 1 and [bge.events.SPACEKEY, bge.logic.KX_INPUT_ACTIVE] in keySens.events):
- if ori[0] > 0:
- ori[0] -= 1 #own["pitchRate"]
- elif ori[0] < 0:
- ori[0] += 1 #own["pitchRate"]
- if ori[1] > 0:
- ori[1] -= 1 #own["rollRate"]
- elif ori[1] < 0:
- ori[1] += 1 #own["rollRate"]
- ori[0] = int(ori[0])
- ori[1] = int(ori[1])
- Util.setRotInDegrees(ori, own)
- else: #We are in 'Flight sim' mode
- if [bge.events.LEFTARROWKEY, bge.logic.KX_INPUT_ACTIVE] in keySens.events:
- #ori[1] -= own["rollRate"]
- #Util.setRotInDegrees(ori, own)
- own.applyTorque([0, -own['rollRate'], 0], True)
- elif [bge.events.RIGHTARROWKEY, bge.logic.KX_INPUT_ACTIVE] in keySens.events:
- #ori[1] += own["rollRate"]
- #Util.setRotInDegrees(ori, own)
- own.applyTorque([0, own['rollRate'], 0], True)
- if [bge.events.UPARROWKEY, bge.logic.KX_INPUT_ACTIVE] in keySens.events:
- #ori[0] -= own["pitchRate"]
- #Util.setRotInDegrees(ori, own)
- own.applyTorque([-own['pitchRate'], 0, 0], True)
- elif [bge.events.DOWNARROWKEY, bge.logic.KX_INPUT_ACTIVE] in keySens.events:
- #ori[0] += own["pitchRate"]
- #Util.setRotInDegrees(ori, own)
- own.applyTorque([own['pitchRate'], 0, 0], True)
- own["XRot"] = ori[0]
- own["YRot"] = ori[1]
- own["ZRot"] = ori[2]
- ############## Movement handling ##############
- #Since this script is run every logic tick (and
- # since it's the "Dragon Controller" script),
- # I don't think there's a better place in which
- # to run the necessary physics, do you?
- if [bge.events.SPACEKEY, bge.logic.KX_INPUT_ACTIVE] in keySens.events:
- #own.applyForce([0, 35, 9.8125], True)
- ##Avar's script##
- AltitudeOut = own['alt']
- VelocityOut = own.getLinearVelocity(True)[1]
- AltitudeIn = own['alt']
- VelocityIn = own.getLinearVelocity(True)[1]
- #AltitudeIn = AltitudeOut
- #VelocityIn = VelocityOut
- ThrustF = 12000
- Area = 4.0875
- DragCoefficient = 0.2295
- ## Density in kilograms per cubic meter
- Density = 55
- ## Mass in kilograms: SI units used
- Mass = own.mass
- CompressionCoefficient = 0.1
- Pitch = Util.getRotInDegrees(own)[0]
- TurnCoefficient = 1
- g = 9.8
- AtmCeil = 90000
- DragF = DragCoefficient * ((Density * VelocityIn ** 2) / 2) * Area + (ThrustF * VelocityIn * 0.005)
- Acceleration = (ThrustF - DragF) / Mass
- VelocityOut = VelocityIn + Acceleration
- DragF = DragCoefficient * ((Density * VelocityIn ** 2) / 2) * Area + (ThrustF * VelocityOut * 0.005)
- #Acceleration = (ThrustF - DragF) / Mass
- VelocityOut = VelocityIn + Acceleration
- Climb = ((math.tan(Pitch)) * ThrustF / Mass) - g
- #VelocityP = round(VelocityOut * 2.234, 2)
- ##End Avar's Script##
- own.applyForce([0, VelocityOut, Climb], True)
- else:
- own.applyForce([0, 0, 9.8]) #Negate gravity's effect
Advertisement
Add Comment
Please, Sign In to add comment