Vehicle Wrapper -- Blender 3D Game Engine


 
pageok
  
1.  Add Powertrain.py to the Text Editor

Download:

Text Editor menu >> Text >> Open
Rename Powertrain249.txt to Powertrain.py
 


  
2.  Powertrain.py --- Brakes  (Line Numbers:  45 - 83)


########################################################  Brakes

def Brakes(vehicleID, controller):

    # set braking amount
    brakeAmount = 40.0      # front and back brakes
    ebrakeAmount = 100.0    # back brakes only 

    # get sensors
    reverse = controller.sensors["Reverse"]        # sensor named "Reverse"
    brake = controller.sensors["Brake"]              # sensor named "Brake
    emergency = controller.sensors["EBrake"]    # sensor named "EBrake"
   
    # emergency brakes       
    if emergency.positive == True:
    
        front_Brake = 0.0
        back_Brake = ebrakeAmount
        brakes = True
   
    # brake  (brake uses Downarrow.  Reverse uses Downarrow + LeftCtrl)
    elif brake.positive == True and reverse.positive == False:
       
        front_Brake = brakeAmount
        back_Brake = brakeAmount
        brakes = True

    # no brakes
    else:
       
        front_Brake = 0.0
        back_Brake = 0.0
        brakes = False

    # brakes   
    vehicleID.applyBraking( front_Brake, 0)
    vehicleID.applyBraking( front_Brake, 1)
    vehicleID.applyBraking( back_Brake, 2)
    vehicleID.applyBraking( back_Brake, 3)

    return brakes

   
   
3.  Powertrain.py --- Power  (Line Numbers:  85 - 122)


########################################################  Gas and Reverse

# gas and reverse   
def Power( vehicleID, controller, brakes):   
   
    # set power amounts
    gasPower = 800.0
    reversePower = 200.0

    # get power sensors
    gas = controller.sensors["Gas"]                     # sensor named "Gas"
    reverse = controller.sensors["Reverse"]        # sensor named "Reverse"
   
    # brakes being used.  No power
    if brakes == True:
       
        power = 0.0
                   
    # reverse
    elif reverse.positive == True:
       
        power = reversePower
   
    # gas pedal
    elif gas.positive == True:
       
        power = -gasPower
   
    # no gas and no reverse
    else:
       
        power = 0.0

    # apply power
    vehicleID.applyEngineForce( power, 0)
    vehicleID.applyEngineForce( power, 1)
    vehicleID.applyEngineForce( power, 2)
    vehicleID.applyEngineForce( power, 3)                                       
       

 
pageok