Physics Constraints 6 DOF Linear Motor: createConstraint

createConstraint(obj1_ID, obj2_ID, constraintType, pivotPos_X, pivotPos_Y, pivotPos_Z)
  • Creates a 6 Degrees Of Freedom Linear Motor Constraint

obj1_ID:
  • The physics ID of object 1.
  • Object 1 is used as the 6DOF anchor/pivot point. 
obj2_ID:
  • The physics ID of object 2.

Constraint Type:

  • 0 = No Constraint
  • 1 = bge.constraints.POINTTOPOINT_CONSTRAINT
  • 2 = bge.constraints.LINEHINGE_CONSTRAINT
     
  • 3 = bge.constraints.ANGULAR_CONSTRAINT
     
  • 4 = bge.constraints.CONETWIST_CONSTRAINT
  • 11 = bge.constraints.VEHICLE_CONSTRAINT
  • 12 = bge.constraints.GENERIC_6DOF_CONSTRAINT (6 Degrees Of Freedom)

pivotPos_X:

  • The x axis position of the pivot.
  • X distance (in Blender Units) from the obj1 object center
pivotPos_Y:
  • The y axis position of the pivot.
  • Y distance (in Blender Units) from the obj1 object center
pivotPos_Z:
  • The z axis position of the pivot.
  • Z distance (in Blender Units) from the obj1 object center
Example Blend:
Sample Code

#################### Create a 6 DOF Linear Motor Constraint

# import bge
import bge

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

# get object list
objList = scene.objects

# get object named Cube_Green
obj1 = objList["Cube_Green"]

# get object named Cube_Red
obj2 = objList["Cube_Red"]

# want to use a 6DOF constraint
constraintType = bge.constraints.GENERIC_6DOF_CONSTRAINT

# get obj1 physics ID
obj1_ID = obj1.getPhysicsId()

# get obj2 physics ID
obj2_ID = obj2.getPhysicsId()

# Use center of obj1 for pivot point
pivotPos_X =  0.0
pivotPos_Y =  0.0
pivotPos_Z =  0.0

# create a 6DOF constraint
cube_6DOF = bge.constraints.createConstraint( obj1_ID, obj2_ID,
                                     constraintType,
                                     pivotPos_X, pivotPos_Y, pivotPos_Z)


# set distance motor can travel on x axis
# min = 0.0 max = 10.0

cube_6DOF.setParam(0, 0.0, 10.0)

# set rotation around pivot x, y and z axis to zero
cube_6DOF.setParam(3, 0.0, 0.0)
cube_6DOF.setParam(4, 0.0, 0.0)
cube_6DOF.setParam(5, 0.0, 0.0)

# create Translational Motor along the pivot x axis
# speed = -25 and acceleration = 0.1

cube_6DOF.setParam(6, -25.0, 0.1)