Point to Point 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_Red
obj1 = objList["Cube_Red"]

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

# want to use a point to point constraint
constraintType = 1

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

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

# Use front bottom right corner of obj1 for pivot point
pointPos_X = 1.0
pointPos_Y = -1.0
pointPos_Z = -1.0

# create a point to point constraint
cube_PtoP = bge.constraints.createConstraint( obj1_ID, obj2_ID, constraintType,
pointPos_X, pointPos_Y, pointPos_Z )
 
# get the constraint ID
point_id= cube_PtoP.constraint_id

# save the contstaint id as an obj1 variable
obj1["Point_ID"] = point_id

 
Sample Code: Part 2

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

# import bge
import bge

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

# get object list
objList = scene.objects

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

# get the saved point to point constraint id
id = obj1["Point_ID"]

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