The forcesAndMaterials.py script collides a box and ball into each other through the application of forces to their physics shapes. It also allows the run-time editing of their physics shapes' properties: density, friction, hardness, and bounce. This tutorial steps through code found in that script.
Open up the script forcesAndMaterials.py from the \tutorials\physics directory.
With every press of the spacebar, the box and ball positions are reset and their physics shapes reinitialized with the property values specified by the sliders. In the reset() function you'll see the following lines of code.
The <node3d>.collideNone() call is necessary to delete the current physics shape. If this was not done, each call to <node3d>.collideBox() would accumulate physics shapes, becoming heavier and heavier. We are recreating the box physics shape object every reset because the scale of the box may have been changed. We also save the returned VizPhysicsShape object in a variable so that we can modify its properties later.
The above code retrieves the position of the sliders with <node3d:GUI:slider>.get() and sets the VizPhysicsShape object's appropriate properties.
We now apply the force that will cause the box to move towards the ball.
The dir parameter is the force vector. Force vectors determine the power and the direction of the force. The duration argument is how long the force will be applied. The pos parameter is the origin of force vector.
The rest of the code in the reset() function sets the commands for the ball.