Class KX_PyConstraintBinding (2.48)


Methods
createConstraint setGravity
getAppliedImpulse setLinearAirDamping
getVehicleConstraint setNumIterations
removeConstraint setNumTimeSubSteps
setCcdMode setSolverDamping
setContactBreakingTreshold setSolverTau
setDeactivationAngularTreshold setSolverType
setDeactivationLinearTreshold setSorConstant
setDeactivationTime setUseEpa
setDebugMode ----------
 
Variables
---------- ----------
 
Constants
---------- ----------


Methods



createConstraint

(Edge Constraint)


createConstraint( obj1_PhysicsID,
obj2_PhysicsID,
constraintType,

edgePos_x,  edgePos_y, edgePos_z,

edgeAngle_x, edgeAngle_y, edgeAngle_z )

obj1_PhysicsID:
Type:  integer
(The physics ID of object 1)

obj2_PhysicsID:
Type:  integer
(The physics ID of object 2)

constraintType:
Type:  integer
0 = No constraint.
1 = Point constraint.
2 = Edge constraint.
11 = Vehicle constraint

edgePos_x:
Type:  float (Blender unit)
edgePos_y:
Type:  float (Blender unit)
edgePos_z:
Type:  float (Blender unit)

edgeAngle_x:
Type:  float
Range:  -1.0 to 1.0  (cosine of the angle)
edgeAngle_y
Type:  float
Range:  -1.0 to 1.0  (cosine of the angle ???)
edgeAngle_z:
Type:  float
Range:  -1.0 to 1.0  (cosine of the angle ???)

Note:
Position (edgePos_x,  edgePos_y, edgePos_z)
Where do you want the center of the edge to be located?  (Distance from obj1's object center)

Note:
Angle (edgeAngle_x, edgeAngle_y, edgeAngle_z)
In what direction do you want the edge to point?  (Uses obj1's axis)

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# get object list
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Obj_1
obj1 = objList["OBObj_1"]

# get object named Obj_2
obj2 = objList["OBObj_2"]

# want to use Edge constraint type
constraintType = 2

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

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

# Use bottom right edge of 0bj_1 for hinge position
edgePos_x = 1.0
edgePos_y = 0.0
edgePos_z = -1.0

# use Obj_1 y axis for angle to point hinge
edgeAngle_x = 0.0
edgeAngle_y = 1.0
edgeAngle_z = 0.0

# create an edge constraint
PhysicsConstraints.createConstraint( obj1_ID, obj2_ID,
     constraintType,
     edgePos_x, edgePos_y, edgePos_z,
     edgeAngle_x, edgeAngle_y, edgeAngle_z )


Example Blend:


createConstraint

(Point Constraint)


createConstraint(   obj1_PhysicsID,

obj2_PhysicsID,
constraintType,
pointPos_x,  pointPos_y, pointPos_z)

obj1_PhysicsID:
Type:  integer
(The physics ID of object 1)

obj2_PhysicsID:
Type:  integer
(The physics ID of object 2)

constraintType:
 Type:    integer

0 = No constraint.
1 = Point constraint.
2 = Edge constraint.
11 = Vehicle constraint

pointPos_x:
Type:  float (Blender unit)
pointPos_y:
Type:  float (Blender unit)
pointPos_z:
Type:  float (Blender unit)

Note:
Point Position (pointPos_x,  pointPos_y, pointPos_z)

Where do you want the pivot point to be located?
(Distance from obj1's object center)

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# get object list
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Obj_1
obj1 = objList["OBObj_1"]

# get object named Obj_2
obj2 = objList["OBObj_2"]

# want to use point constraint type
constraintType = 1

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

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

# Use bottom right front corner of obj1 for point position
pointPos_x = 1.0
pointPos_y = -1.0
pointPos_z = -1.0

# create a point constraint
PhysicsConstraints.createConstraint( obj1_ID, obj2_ID,
     constraintType,
     pointPos_x, pointPos_y, pointPos_z)


Example Blend:


createConstraint

(Vehicle Constraint)


createConstraint(obj1_PhysicsID,

obj2_PhysicsID,
constraintType )

obj1_PhysicsID:
Type:  integer
(The physics ID of the vehicle)

obj2_PhysicsID:
Type:  integer  (Set this to 0 (zero))

constraintType:
   Type:  integer
0 = No constraint.
1 = Point constraint.
2 = Edge constraint.
11 = Vehicle constraint.

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# get object list
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Car
objCar = objList["OBCar"]

# want to use vehicle constraint type
constraintType = 11

# get car physics ID
carID = objCar.getPhysicsId()

# create a vehicle constraint
PhysicsConstraints.createConstraint( carID, 0, constraintType)


Example Blend:


getAppliedImpulse

getAppliedImpulse(constraintId)

Returns the applied impulse.

Return type:  float

constraintId:
Type:  integer

Note:
Save the constraintID when the constraint is created.

Sample Code


1st script

# import PhysicConstraints Module
import PhysicsConstraints

# get object list
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Car
objCar = objList["OBCar"]

# want to use vehicle constraint type
constraintType = 11

# get car physics ID
car_ID = objCar.getPhysicsId()

# create a vehicle constraint
carConst = PhysicsConstraints.createConstraint( car_ID, 0, constraintType)
  
# get the constraint ID
carConst_ID = carConst.getConstraintId()                                  

# save the constraint ID as a objCar variable
objCar.constraint_ID = carConst_ID

#### rest of 1st script


2nd script

# import PhysicConstraints Module
import PhysicsConstraints

# get object list
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Car
objCar = objList["OBCar"]

# get car constraint ID that was saved
carConst_ID = objCar.constraint_ID

# get the applied impulse
appliedImpulse = PhysicsConstraints.getAppliedImpulse(carConst_ID)


getVehicleConstraint

getVehicleConstraint(constraint_ID)

Returns the vehicle constraint ID.

constraint_ID:
Type:  integer

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# get object list
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Car
objCar = objList["OBCar"]

# want to use vehicle constraint type
constraintType = 11

# get car physics ID
car_ID = objCar.getPhysicsId()

# create a vehicle constraint
carConst = PhysicsConstraints.createConstraint( car_ID, 0, constraintType)
  
# get the constraint ID
carConst_ID = carConst.getConstraintId()

# get vehicle constraint
car = PhysicsConstraints.getVehicleConstraint(carConst_ID)

removeConstraint

removeConstraint(constraint_ID)

Removes the constraint.

constraint_ID
Type:  integer

Note:
Save the constraintID when the constraint is created.

Note:
This removes the constraint between 2 game objects (point and edge constraints).  It does not remove vehicle constraints.

Sample Code

Part 1: Create a Point Constraint

#########  PointConstraint.py

# import PhysicConstraints Module
import PhysicsConstraints

# get object list
objList = GameLogic.getCurrentScene().getObjectList()

# get object named Obj_1
obj1 = objList["OBObj_1"]

# get object named Obj_2
obj2 = objList["OBObj_2"]

# use point constraint type
constraintType = 1

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

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

# Use bottom right front corner of obj1 for point position
pointPos_x = 1.0
pointPos_y = -1.0
pointPos_z = -1.0

# create a point constraint
constraint = PhysicsConstraints.createConstraint( obj1_ID, obj2_ID,
     constraintType,
     pointPos_x, pointPos_y, pointPos_z)

# get the constraint ID
constraint_ID = constraint.getConstraintId()

# save the constraint ID as an Obj_1 variable
obj1.constraint_ID = constraint_ID

Part 2: Remove constraint script

###########  RemoveConstraint.py

# import PhysicConstraints Module
import PhysicsConstraints

# get object list
objList = GameLogic.getCurrentScene().getObjectList()

# get object 1
obj1 = objList["OBObj_1"]

# get constraint ID that was saved as an Obj_1 variable
# when the constraint was created
constraint_ID = obj1.constraint_ID

# remove constraint
PhysicsConstraints.removeConstraint(constraint_ID)


Example Blend:


setCcdMode

setCcdMode(int ccdMode)

Experimental

setContactBreakingTreshold

setContactBreakingTreshold(float breakingTreshold)

Experimental

setDeactivationAngularTreshold

setDeactivationAngularTreshold(angularTreshold)

Sets the angular velocity that an object must be below before the deactivation timer can start.

angularTreshold:
Type:  float

Note:
This affects every object in the scene, except for game objects that have 'No sleeping' turned on.

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# set the deactivation angular velocity threshold
PhysicsConstraints.setDeactivationAngularTreshold(1.0)

setDeactivationLinearTreshold

setDeactivationLinearTreshold(linearTreshold)

Sets the linear velocity that an object must be below before the deactivation timer can start.

linearTreshold:
Type:  float

Note:
This affects every object in the scene, except for game objects that have 'No sleeping' turned on.

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# set the deactivation linear velocity threshold
PhysicsConstraints.setDeactivationLinearTreshold(1.0)

setDeactivationTime

setDeactivationTime(time)

Sets the amount of time that an object must stay below the velocity thresholds before the object enters sleep mode.

time:
Type:  float  (seconds)

Note:
This affects every object in the scene, except for game objects that have 'No sleeping' turned on.

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# set the deactivation time
PhysicsConstraints.setDeactivationTime(1.0)

setDebugMode

setDebugMode(mode)

Experimental

setGravity

setGravity(gx, gy, gz)

Sets the gravity for the scene.

gx:
Type:  float
(force of gravity on world x axis)
gy:
Type:  float
(force of gravity on world y axis)
gz:
Type:  float
(force of gravity on world z axis)

Note:
This affects every object in the scene that has physics enabled.

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# Beam me up!!
# set gravity to a +10.0 on z axis
PhysicsConstraints.setGravity( 0.0, 0.0, 10.0)   


Example Blend:


setLinearAirDamping

setLinearAirDamping(damping)

Sets the linear air resistance for all objects in the scene.

damping:
Type:  float

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# set linear air resistance to 30.0
PhysicsConstraints.setLinearAirDamping(30.0)

setNumIterations

setNumIterations(numIter)

Sets the number of times an iterative constraint solver is repeated.

numIter:
Type:  integer

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# repeat iterative solvers 10 times
PhysicsConstraints.setNumIterations(10)

setNumTimeSubSteps

setNumTimeSubSteps(numSubStep)

Sets the number of time sub steps.  (This increases the accuracy of the physics but decreases the game framerate.)

numSubStep
Type:  integer

Sample Code

# import PhysicConstraints Module
import PhysicsConstraints

# set time sub steps to 2
PhysicsConstraints.setNumTimeSubSteps(2)

setSolverDamping

setSolverDamping(float damping)

Experimental

setSolverTau

setSolverTau(float tau)

Experimental

setSolverType

setSolverType(int solverType)

Experimental


setSorConstant

setSorConstant(float sor)

Experimental

setUseEpa

setUseEpa( int epa)

Experimental




Blender 3D
Game Engine