rst bge touch ups: making the title of the examples slightly more noticeable
[blender.git] / doc / python_api / examples / bge.constraints.py
1 """
2 Basic Physics Constraint
3 ++++++++++++++++++++++++
4 Example of how to create a hinge Physics Constraint between two objects.
5 """
6 from bge import logic
7 from bge import constraints
8
9 # get object list
10 objects = logic.getCurrentScene().objects
11
12 # get object named Object1 and Object 2
13 object_1 = objects["Object1"]
14 object_2 = objects["Object2"]
15
16 # want to use Edge constraint type
17 constraint_type = 2
18
19 # get Object1 and Object2 physics IDs
20 physics_id_1 = object_1.getPhysicsId()
21 physics_id_2 = object_2.getPhysicsId()
22
23 # Use bottom right edge of Object1 for hinge position
24 edge_position_x = 1.0
25 edge_position_y = 0.0
26 edge_position_z = -1.0
27
28 # use Object1 y axis for angle to point hinge
29 edge_angle_x = 0.0
30 edge_angle_y = 1.0
31 edge_angle_z = 0.0
32
33 # create an edge constraint
34 constraints.createConstraint(physics_id_1, physics_id_2,
35                              constraint_type,
36                              edge_position_x, edge_position_y, edge_position_z,
37                              edge_angle_x, edge_angle_y, edge_angle_z)