Blender 3D game engine: KX_VehicleWrapper
Methods:
addWheel getWheelRotation
applyBraking setRollInfluence
applyEngineForce setSteeringValue
getConstraintId setSuspensionCompression
getConstraintType setSuspensionDamping
getNumWheels setSuspensionStiffness
getWheelOrientationQuaternion setTyreFriction
getWheelPosition ----------
Variables:
---------- ----------
Constants:
---------- ----------
Inherited
Methods:
isA ----------



Instance Methods

addWheel


addWheel(wheel, wheelPos, axlePos, wheelAxis,
  suspensionHeight, wheelRadius, steering)

Adds a wheel to the vehicle.

wheel:
Type:  KX_GameObject
(The game model of the tire.)

wheelPos:
Tire position from vehicle object center.
Type:  float list [ x, y, z]
Uses local x, y, z float values.

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 used to attach it to the axle.
Type:  float list [ xAxis, yAxis, zAxis]
Range -1.0 to 1.0 

suspensionHeight:
Height of the suspension.  Local value.
Type:  float.

wheelRadius:
Radius of the tire.
Type:  float

steering:
   Type:   Bool
True or 1 = tire used for steering.
False or 0 = tire not used for steering.

Sample Code

#import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get vehicle object named car
objCar = objList["OBCar"]
   
# keep the vehicle active, otherwise simulation stops
objCar.applyImpulse([ 0.0, 0.0, 0.0], [ 0.0, 0.0, 0.0])
   
# get car physics ID
car_PhysicsID = objCar.getPhysicsId()
 
# create a vehicle constraint
vehicle_Constraint = PhysicsConstraints.createConstraint(car_PhysicsID, 0, 11)
 
# get the constraint ID
constraint_ID = vehicle_Constraint.getConstraintId()

# save constraint_ID as a car variable
objCar.constraint_ID = constraint_ID

# get the vehicle constraint ID
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# use the object names to get the tires
tire_FD = objList["OBTire_1"]
tire_FP = objList["OBTire_2"]
tire_RD = objList["OBTire_3"]
tire_RP = objList["OBTire_4"]

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

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

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

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

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

# tire axis attached to car axle
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 (tire 0)
vehicle.addWheel( tire_FD, tirePos_FD, suspension_Angle, tireAxis,
                      suspensionHeight_FD,  tireRadius_FD, tireSteer_FD )

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

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

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

Example Blend

Example Blend:    AddWheel.blend

applyBraking

applyBraking(force, wheel)

Applies a braking force to a wheel.

force:
Type:  float

wheel:
  Type:   integer
0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID

# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)
 
# set braking force
force = 10.0

# brake with all four tires
vehicle.applyBraking( force, 0)
vehicle.applyBraking( force, 1)
vehicle.applyBraking( force, 2)
vehicle.applyBraking( force, 3)

applyEngineForce

applyEngineForce( force, wheel)

Applies a force to the wheel's y-axis.

force:
Type:  float

wheel:
   Type:  integer
0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID

# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# set engine force
power = 100.0

# apply to all four tires
vehicle.applyEngineForce( power, 0)
vehicle.applyEngineForce( power, 1)
vehicle.applyEngineForce( power, 2)
vehicle.applyEngineForce( power, 3)

getConstraintId

getConstraintId()

Returns the constraint ID

Return Type:  integer

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Car
objCar = objList["OBCar"]

# Get the physics ID
objCar_ID = objCar.getPhysicsId()
 
# create a vehicle constraint
car = PhysicsConstraints.createConstraint(objCar_ID, 0, 11)
 
# get the constraint ID
constraint_ID = car.getConstraintId()

# save constraint_ID as a car variable
objCar.constraint_ID = constraint_ID

getConstraintType

getConstraintType()

Returns the constraint type.

Return Type:  integer

0 = No constraint.
1 = Point constraint.
2 = Edge constraint.
11 = Vehicle constraint

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID

# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)
 
constrType = vehicle.getConstraintType()

getNumWheels

getNumWheels()

Returns the number of wheels that have been added to the vehicle.

Return type:  integer

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID

# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# get the number of wheels
numWheels = vehicle.getNumWheels()

getWheelOrientationQuaternion

getWheelOrientationQuaternion(wheel)

Returns the wheel orientation matrix.

Return type:  3x3 orientation matrix.

wheel:
   Type:  integer

0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get vehicle named car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID

# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# get tire orientation of 1st tire added
tireOrient = vehicle.getWheelOrientationQuaternion(0)

getWheelPosition

getWheelPosition(wheel)

Returns the position of the wheel.

Return type:  float list [ x, y, z]

wheel:
   Type:  integer

0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get vehicle named car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID

# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# wheel position of the first tire added
wheelPos = vehicle.getWheelPosition(0)

getWheelRotation

getWheelRotation(wheel)

Returns the distance (in Blender Units) the tire has traveled.

Return type:  float

wheel:
   Type:  integer

0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Note:
This works like your car odometer.  Forward adds to the distance.  Reverse substracts.

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get vehicle named car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID

# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# get the distance 1st tire has traveled
odometer = vehicle.getWheelRotation(0)

setRollInfluence

setRollInfluence( roll, wheel)

Sets how much it rolls (leans) to the side.

roll:
Type:  float

wheel:
  Type:   integer

0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get vehicle named car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID
 
# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# 1st tire added
vehicle.setRollInfluence(0.2, 0)

# 2nd tire added
vehicle.setRollInfluence(0.2, 1)

# 3rd tire added
vehicle.setRollInfluence(0.2, 2)

# 4th tire added
vehicle.setRollInfluence(0.2, 3)

setSteeringValue

setSteeringValue(amount, wheel)

Turns the tire for steering.

amount:
  Type:   float

0.1 approximately 10 degrees
0.2 approximately 20 degrees
etc.

wheel:
  Type:    integer

0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get vehicle named car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID
 
# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# frontLeftTire was first added.
vehicle.setSteeringValue( 0.3, 0)

# frontRightTire was second added.
vehicle.setSteeringValue( 0.3, 1)

setSuspensionCompression

setSuspensionCompression( compress, wheel)

Sets how much the suspension compresses.

compress:
   Type:  float

wheel:
   Type:  integer

0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get vehicle named car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID
 
# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# 1st tire added
vehicle.setSuspensionCompression(1.5, 0)

# 2nd tire added
vehicle.setSuspensionCompression(1.5, 1)

# 3rd tire added
vehicle.setSuspensionCompression(1.5, 2)

# 4th tire added
vehicle.setSuspensionCompression(1.5, 3)

setSuspensionDamping

setSuspensionDamping(damping, wheel)

Sets the suspension damping.

damping:
   Type:  float

wheel:
   Type:  integer

0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get vehicle named car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID
 
# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# 1st tire added
vehicle.setSuspensionDamping(4.5, 0)

# 2nd tire added
vehicle.setSuspensionDamping(4.5, 1)

# 3rd tire added
vehicle.setSuspensionDamping(4.5, 2)

# 4th tire added
vehicle.setSuspensionDamping(4.5, 3)

setSuspensionStiffness

setSuspensionStiffness(stiffness, wheel)

Sets the suspension stiffness.

stiffness:
   Type:  float

wheel:
   Type:  integer
0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get vehicle named car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when the wheels were attached
constraint_ID = objCar.constraint_ID
 
# get the vehicle constraint
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# 1st tire added.
vehicle.setSuspensionStiffness(8.5, 0)

# 2nd tire added.
vehicle.setSuspensionStiffness(8.5, 1)

# 3rd tire added.
vehicle.setSuspensionStiffness(8.5, 2)

# 4th tire added.
vehicle.setSuspensionStiffness(8.5, 3)

setTyreFriction

setTyreFriction(friction, wheel)

Sets the tire friction.

friction:
   Type:  float

wheel:
   Type:  integer

0 = first wheel added
1 = second wheel added
2 = third wheel added
3 = fourth wheel added

Sample Code

# import PhysicsConstraints
import PhysicsConstraints

# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()

# get vehicle named car
objCar = objList["OBCar"]

# Retrieve constraint ID you saved when wheels were attached
constraint_ID = objCar.constraint_ID

# get the vehicle constraint ID
vehicle = PhysicsConstraints.getVehicleConstraint(constraint_ID)

# 1st tire added.
vehicle.setTyreFriction(4.5, 0)

# 2nd tire added.
vehicle.setTyreFriction(4.5, 1)

# 3rd tire added.
vehicle.setTyreFriction(4.5, 2)

# 4th tire added.
vehicle.setTyreFriction(4.5, 3)





isA

isA(Type)

Checks the Object type.
(KX_GameObject, SCA_ILogicBrick, KX_Scene, etc.)

Type:  String

Return Type:  Bool
1 = True
0 = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get the object controller attached to
owner = controller.getOwner()

# is owner a GameObject?
gameObject = owner.isA("KX_GameObject")


Blender 3D
Game Engine
Rapid prototyping for 3D games. Test realtime 3D gameplay without having to compile the game code. 3D game models automatically added.  GLSL shaders. Normal Mapping and Parallax Mapping. All OpenGL Lighting modes. This includes transparencies, animated and reflection mapped textures. Multiple textures and materials. UV mapping. Per-pixel lighting and dynamic lighting.  Uses Bullet Physics. Soft body dynamics. Rigid body dynamics. Collision detection and dynamics simulation. Collision bounds of all types. Car physics engine with full support for vehicle dynamics. (Spring reactions, stiffness, damping, tire friction etc.).