Vehicle Constraint: addWheel

addWheel(wheelMesh, wheelPos, axlePos, wheelAxis, suspensionHeight, wheelRadius, steering)
  • Adds one wheel to the vehicle.

wheelMesh:
  • The game model of the tire.
  • Type:  KX_GameObject
wheelPos:
  • Tire position (distance from vehicle object center).
  • Type:  float list [ x, y, z]
suspensionAngle:
  • Cosine of the angle (uses vehicle object center axis)
  • Type:  float list [x, y, z]
  • Range  -1.0 to 1.0
wheelAxis:
  • Axis of the tire object used to attach it to the axle.
  • Type: cosine float list [ xAxis, yAxis, zAxis]
  • Range -1.0 to 1.0 
suspensionHeight:
  • Height of the suspension. 
  • Type:  float.
wheelRadius:
  • Radius of the tire.
  • Type:  float
steering:
  • Type: Boolean
  • 1 = True = tire used for steering.
  • 0 = False = tire not used for steering.
Note:
  • The wheel mesh isn't the actual tire.  It is just a 'skin' for the tire that the vehicle wrapper automatically creates for you.
     
  • You can use an empty, Suzanne mesh, a rock mesh, a bottle mesh, etc.  Anything you want.  It only changes the way the wheel looks.  It doesn't change the actual wheel that the vehicle wrapper automatically added.
Sample Code

################ add the tires

#import bge
import bge

# get current scene
scene = bge.logic.getCurrentScene()

# get object list
objList = scene.objects

# get my vehicle object named car
obj1 = objList["Car"]
    
# get obj1 physics ID
obj1_ID = obj1.getPhysicsId()

# there isn't any obj 2
obj2_ID = 0

# want to use a vehicle constraint
constraintType = 11

# create a vehicle constraint
vehicle_Constraint = bge.constraints.createConstraint( obj1_ID, obj2_ID, constraintType ) 
 
# get the constraint ID
constraint_ID = vehicle_Constraint.constraint_id

# create the vehicle
vehicle = bge.constraints.getVehicleConstraint(constraint_ID)

# use the object names to get the tire skins
tire_FD = objList["Tire_1"]
tire_FP = objList["Tire_2"]
tire_RD = objList["Tire_3"]
tire_RP = objList["Tire_4"]

# My front driver tire position from car object center
tirePos_FD = [ -2.0, 4.0, -2.0]

# My front passenger tire position from car object center
tirePos_FP = [ 2.0, 4.0, -2.0]

# My rear driver tire position from car object center
tirePos_RD = [ -2.0, -4.0, -2.0]

# My rear passenger tire position from car object center
tirePos_RP = [ 2.0, -4.0, -2.0]

# suspension angle from car object center
# using -z axis
suspension_Angle = [ 0.0, 0.0, -1.0]

# tire axis attached to car axle
# using -x axis of tire object
tireAxis = [ -1.0, 0.0, 0.0]

# set suspension height
suspensionHeight_FD = 0.2
suspensionHeight_FP = 0.2
suspensionHeight_RD = 0.2
suspensionHeight_RP = 0.2

# set tire radius
tireRadius_FD = 1.0
tireRadius_FP = 1.0
tireRadius_RD = 1.0
tireRadius_RP = 1.0

# tire has steering?
tireSteer_FD = True
tireSteer_FP = True
tireSteer_RD = False
tireSteer_RP = False

# Add front driver tire
vehicle.addWheel( tire_FD, tirePos_FD, suspension_Angle, tireAxis,
                           suspensionHeight_FD,  tireRadius_FD, tireSteer_FD )

# Add front passenger tire
vehicle.addWheel( tire_FP, tirePos_FP, suspension_Angle, tireAxis,
 suspensionHeight_FP,  tireRadius_FP, tireSteer_FP )

# Add rear driver tire
vehicle.addWheel( tire_RD, tirePos_RD, suspension_Angle, tireAxis,
 suspensionHeight_RD,  tireRadius_RD, tireSteer_RD )

# Add rear passenger tire
vehicle.addWheel( tire_RP, tirePos_RP, suspension_Angle, tireAxis,
 suspensionHeight_RP,  tireRadius_RP, tireSteer_RP )