Vehicle Constraint: applyEngineForce

applyEngineForce( power, wheel)
  • Applies the power to the wheel's y-axis.

power:
  • engine power
  • Type:  float
wheel:
  • wheel to apply the engine power to.
  • Type:  integer
  • 0 = first wheel added
  • 1 = second wheel added
  • 2 = third wheel added
  • 3 = fourth wheel added
Note:
  • applyEngineForce is persistent.
     
  • Once you apply the engine power, it stays applied.
     
  • To remove the engine power, use a power of 0.0 (zero).
Sample Code

################ apply the engine power

#import bge
import bge

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

# get object list
objList = scene.objects

# get vehicle object named car
objCar = objList["Car"]
    
# Retrieve constraint ID you saved as a property when you created the vehicle constraint
constraint_ID = objCar["constraint_ID"]

# get the vehicle
vehicle = bge.constraints.getVehicleConstraint(constraint_ID)
 
# set engine power
power = 100.0

# vehicle has 4 wheel drive
vehicle.applyEngineForce( power, 0)
vehicle.applyEngineForce( power, 1)
vehicle.applyEngineForce( power, 2)
vehicle.applyEngineForce( power, 3)

Sample Code

################ take foot off the gas pedal

#import bge
import bge

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

# get object list
objList = scene.objects

# get vehicle object named car
objCar = objList["Car"]
    
# Retrieve constraint ID you saved as a property when you created the vehicle constraint
constraint_ID = objCar["constraint_ID"]

# get the vehicle
vehicle = bge.constraints.getVehicleConstraint(constraint_ID)
 
# set the engine power to 0
power = 0.0

# release the brakes for all four tires
vehicle.applyEngineForce( power, 0)
vehicle.applyEngineForce( power, 1)
vehicle.applyEngineForce( power, 2)
vehicle.applyEngineForce( power, 3)