0
$\begingroup$

The code below is not working.
In the system console it says no module named PhysicsConstraints

import PhysicsConstraints
from bge import logic

cont = logic.getCurrentController()
c  = cont.owner

if (c["init"] == 0):
    c["init"] = 1
    physicsid = c.getPhysicsId()
    vehicle = PhysicsConstraints.createConstraint(physicsid,0,11)
    c["cid"] = vehicle.getConstraintId()
    vehicle = PhysicsConstraints.getVehicleConstraint(c["cid"])

# Wheels

    act1 = cont.actuators["wheel1"]
    wheel1 = act1.owner

    act2 = cont.actuators["wheel2"]
    wheel2 = act2.owner

    act3 = cont.actuators["wheel3"]
    wheel3 = act3.owner

    act4 = cont.actuators["wheel4"]
    wheel4 = act4.owner


    wheelAttachDirLocal = [0,0,-1]
    wheelAxleLocal = [-1,0,0]

    wheelRadius = 0.8
    suspensionRestLength = 0.28


    hasSteering = 1
# wheel1
    wheelAttachPosLocal = [1.0 ,1.5, 0]
    vehicle.addWheel(wheel1,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionRestLength,wheelRadius,hasSteering)
# wheel 2
    wheelAttachPosLocal = [-1.0 ,1.5, 0]
    vehicle.addWheel(wheel2,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionRestLength,wheelRadius,hasSteering)


    hasSteering = 0
# wheel 3
    wheelAttachPosLocal = [1.0 ,-1.4, 0]
    vehicle.addWheel(wheel3,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionRestLength,wheelRadius,hasSteering)
# wheel 4
    wheelAttachPosLocal = [-1.0 ,-1.4, 0]
    vehicle.addWheel(wheel4,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionRestLength,wheelRadius,hasSteering)

else:

    vehicle = PhysicsConstraints.getVehicleConstraint(c["cid"])

    #vehicle.setSteeringValue(steer,0)  
    #vehicle.setSteeringValue(steer,1)

# Acceleration

    vehicle.applyEngineForce(c["force"],0)
    vehicle.applyEngineForce(c["force"],1)

# Brakes

    vehicle.applyBraking(c["brake"],0)
    vehicle.applyBraking(c["brake"],1)
    vehicle.applyBraking(c["brake"],2)
    vehicle.applyBraking(c["brake"],3)

# Suspension

    influence = 0.1
    vehicle.setRollInfluence(influence,0)
    vehicle.setRollInfluence(influence,1)
    vehicle.setRollInfluence(influence,2)
    vehicle.setRollInfluence(influence,3)

    stiffness = 10
    vehicle.setSuspensionStiffness(stiffness,0)
    vehicle.setSuspensionStiffness(stiffness,1)
    vehicle.setSuspensionStiffness(stiffness,2)
    vehicle.setSuspensionStiffness(stiffness,3)

    damping = 0.5
    vehicle.setSuspensionDamping(damping,0)
    vehicle.setSuspensionDamping(damping,1)
    vehicle.setSuspensionDamping(damping,2)
    vehicle.setSuspensionDamping(damping,3)

    compression = 0.5
    vehicle.setSuspensionCompression(compression,0)
    vehicle.setSuspensionCompression(compression,1)
    vehicle.setSuspensionCompression(compression,2)
    vehicle.setSuspensionCompression(compression,3)

    friction = 1.0
    vehicle.setTyreFriction(friction,0)
    vehicle.setTyreFriction(friction,1)
    vehicle.setTyreFriction(friction,2)
    vehicle.setTyreFriction(friction,3)


The logic editor window looks like this: enter image description here What should I do to run this code?

$\endgroup$
1
$\begingroup$

replace

import PhysicsConstraints
...
vehicle = PhysicsConstraints.createConstraint(physicsid,0,11)
...

with

import bge.constraints
...
vehicle = bge.constraints.createConstraint(physicsid,0,11)
...

and so on.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.