Line Hinge Constraint: removeConstraint

removeConstraint(constraintID)
  • Removes the constraint that was created.

constraintID: 
  • The id number of the constraint.
     
  • Type: integer
Note:
  • The constraint ID is NOT the same thing as the constraint type.
     
  • The BGE assigns a new--and sometimes different--constraint ID number each time the constraint is created.
Sample Code: Part 1

################ create the 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 Line Hinge constraint
constraintType = 2

# 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

# direction hinge points (same as obj1 y axis)
edgeAngle_x = 0.0
edgeAngle_y = 1.0
edgeAngle_z = 0.0

# create a door hinge (edge) constraint
door_hinge = bge.constraints.createConstraint( obj1_ID, obj2_ID, constraintType,
    edgePos_x, edgePos_y, edgePos_z,
    edgeAngle_x, edgeAngle_y, edgeAngle_z )

# get the constraint ID
hinge_id= door_hinge.constraint_id

# save the id number as a bge global variable
bge.hinge_id = hinge_id
 
Sample Code: Part 2

################ remove the constraint

# import bge
import bge

# get the saved line hinge constraint id
id = bge.hinge_id

# remove the constraint
bge.constraints.removeConstraint(id)