Vehicle Wrapper -- Blender 3D Game Engine


  
pageok

  
4.  Powertrain.py --- Steering  (Line Numbers:  125 - 153)


########################################################  Steering

def Steering( vehicleID, controller):

# set turn amount
turn = 0.3

# get steering sensors
steerLeft = controller.sensors["Left"]        # sensor named "Left"
steerRight = controller.sensors["Right"]    # sensor named "Right"
       
# turn left   
if steerLeft.positive == True:
       
turn = turn
   
# turn right   
elif steerRight.positive == True:
       
turn = -turn
   
# go straight   
else:
turn = 0.0
       
# steer with front tires only
vehicleID.setSteeringValue(turn,0)
vehicleID.setSteeringValue(turn,1)

 
   
5.  Switch to State Mask Group 3

Note:
This tutorial uses State Mask Groups.
State Mask Group 1:  Car Setup  (CarSetup.py)
State Mask Group 2:  Tweak Suspension (Suspension.py)
State Mask Group 3:  Car controls.  (Powertrain.py)

Car selected

Buttons Window menu >> Logic (F4)
Sensors
Enable State button
Controllers
State GUI:  
State Mask Group 3
Actuators
Enable State button

   
6.  Add a Keyboard Sensor to State Mask Group 3:  Name it Gas

Note:
Sensor must be named Gas.  Can't be named Fred or gas or anything else.  The python code looks for sensor attached to the camera named Gas.

Car selected

Buttons Window menu >> Logic (F4)
Sensors
Add
Keyboard
Name:  Gas
Key:  Uparrow


   
7.  Add a Keyboard Sensor to State Mask Group 3:  Name it Brake

Note:
Sensor must be named Brake.  Can't be named Fred or brake or anything else.  The python code looks for sensor attached to the camera named Brake.

Car selected

Buttons Window menu >> Logic (F4)
Sensors
Add
Keyboard
Name:  Brake
Key:  Downarrow


 
pageok