Line Hinge Constraint: createConstraint

createConstraint(obj1_ID, obj2_ID, constraintType,
                             pivotPos_X, pivotPos_Y, pivotPos_Z,
                             rot_X, rot_Y, rot_Z)
  • Creates a line hinge physics constraint

obj1_ID:
  • The physics ID of object 1
  • Object 1 is used as the anchor
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 from the obj1 object center
pivotPos_Y:
  • The y axis position of the pivot
  • Y distance from the obj1 object center
pivotPos_Z:
  • The z axis position of the pivot
  • Z distance from the obj1 object center

rot_X:
  • Rotation in degrees on obj1's x-axis
  • Type:  float
     
  • Range: -360.0 to 360.0 degrees
rot_Y:
  • Rotation in degrees on obj1's y-axis
  • Type:  float
     
  • Range: -360.0 to 360.0 degrees
rot_Z:
  • Rotation in degrees on obj1's z-axis
  • Type:  float
     
  • Range: -360.0 to 360.0 degrees
Note:
  • The Line Hinge starting position (the default) is along obj1's X axis
     
  • To change the orientation of the Line Hinge, you have to rotate it from it's starting position
     
  • To change the orientation of the Line Hinge from obj1's X axis to obj1's Y axis, rotate it (+ or -) 90 degrees on obj1's Z axis
     
  • To change the orientation of the Line Hinge from obj1's X axis to obj1's Z axis, rotate it (+ or -) 90 degrees on obj1's Y axis
Note:
  • Line Hinge on obj1 X-axis:
    • rotation on ob1 x-axis 0.0 degrees: rot_X = 0.0
       
    • rotation on obj1 y-axis 0.0 degrees: rot_Y = 0.0
       
    • rotation on obj1 z-axis 0.0 degrees: rot_Z = 0.0
  • Line Hinge on obj1 Y-axis:
    • rotation on obj1 x-axis 0.0 degrees: rot_X = 0.0
       
    • rotation on obj1 y-axis 0.0 degrees: rot_Y = 0.0
       
    • rotation on obj1 z-axis 90 degrees: rot_Z = 90
  • Line Hinge on obj1 Z-axis:
    • rotation on obj1 x-axis 0.0 degrees: rot_X = 0.0
       
    • rotation on obj1 y-axis -90 degrees: rot_Y = -90.0
       
    • rotation on obj1 z-axis 0.0 degrees: rot_Z = 0.0
Sample Code



################  create a line hinge Constraint on obj1's y axis

# 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 line hinge constraint
constraintType = bge.constraints.LINEHINGE_CONSTRAINT

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

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

# center of hinge position (obj1 bottom right)
edgePos_x = 1.0
edgePos_y = 0.0
edgePos_z = -1.0

# Create a line hinge on obj1 Y-axis
# degree rotation on obj1 x-axis
rot_X = 0.0
# degree rotation on obj1 y-axis
rot_Y = 0.0
# degree rotation on obj1 z-axis
rot_Z = 90.0

# create a door hinge (edge) constraint
bge.constraints.createConstraint( obj1_ID, obj2_ID, constraintType,
edgePos_x, edgePos_y, edgePos_z,
rot_X, rot_Y, rot_Z )