Vehicle Wrapper - Apply Engine Power/Braking

Hello everyone!
After some fiddling with the Vehicle Wrapper and some help, I managed to get a suspension working. (Yay!)

However, the movement is another thing. BluePrintRandom provided me with this script, which also does engine power. (The last lines, in the else: statement)

from bge import logic, constraints

cont = logic.getCurrentController()
scene = logic.getCurrentScene()


own = cont.owner
chassis = own


space = cont.sensors["Space"]


vehicleID = own.getPhysicsId()


if not "init" in own:         
    vehicle = constraints.createVehicle(vehicleID)
    for wheel in chassis.childrenRecursive:
        if "Wheel" in wheel.name:
            #define parameters
            wheelPos = chassis.worldOrientation.inverted() * (wheel.worldPosition - chassis.worldPosition)
            downDir = [0.0, 0.0, -1.0]
            axleDir = [-1.0, 0.0, 0.0]
            #create the wheel
            wheel.removeParent()
            vehicle.addWheel(wheel, wheelPos, downDir, axleDir, 0.25, 1.0, False)
            #save vehicle
            own["Vehicle"] = vehicle
    own["init"] = True
            
else:
    vehicle = own["Vehicle"] 
    if space.positive:
        for wheel in range(vehicle.getNumWheels()):
            vehicle.applyEngineForce(1, wheel)
    else:
        for wheel in range(vehicle.getNumWheels()):
            vehicle.applyBraking(1, wheel)

However, when I press “space”, the vehicle starts accelerating, even though I am no longer pressing “space”. I added the last 2 lines to try to counter this, but it didn’t work. The sensors are working correctly, I used print() to check.

This is probably some stupid, small mitstake, but with my close-to-none of experience with the Vehicle Wrapper, I didn’t find it.

PS: The code could probably use some optimization and better coding, feel free to correct it.

Here is the .blend:

Attachments

VehicleWrapperTest.blend (451 KB)

Nevermind, I solved it! Now I just need to figure out turning and the suspension settings, but it will be easy…