18. Contacts
When two Shapes are in contact, AGX Dynamics automatically generate contact points for these. The contact points are given to the AGX Dynamics solver during Simulation stepping.
The generation of contact points can to some extent be manipulated by the user.
Examples of this is using Collision Groups to disable contact generation between certain Shapes or setting the Contact Reduction Level
in a Contact Material
.
18.1. Contacts Rendering
By enabling the Draw Shape Contacts
setting in Edit > Project Settings... > Plugins > AGX Dynamics > Debug
, all contact points will be rendered on the screen each frame.
This can be helpful for quicly inspecting contact behaviours between objects in a Simulation. Note that this operation is computationally intensive, meaning it should be turned off whenever performance is important.
The Draw Shape Contacts
setting can also be enabled or disabled at runtime by setting it in the AGX Simulation object:
The contact point rendering is mainly a debugging and inspection tool and is not avaiable in built applications built with Shipping
configuration.
For more control over contacts, for rendering or other operations, contact points can be accessed from Blueprint or C++, see Accessing Contact Points.
18.2. Accessing Contact Points
Below, examples of how to access contact points in Blueprints are shown. Accessing contact points from C++ is also supported.
To access contact points for a specific Shape, simply call the GetShapeContacts
function on it.
To access all contact points in the Simulation, call the GetShapeContacts
on the AGX Simulation
object.
18.3. Contact Event Listener
It is possible to listen for contact events emitted by AGX Dynamics while Step Forward is running. This is different from using the Get Shape Contacts function in that it happens during the step instead of after which means that contacts not seen by the solver, e.g. contacts involving Kinematic bodies, are included. Also, it is possible to modify the contacts, for example by altering depth or normal directions, or to disable contacts entirely.
Contact listening is available both as events on AGX Simulation and as overridable functions on the Contact Event Listener Component, which a Blueprint class can inherit from.
For the events on AGX Simulation to trigger Enable Global Contact Event Listener must be enbled in Project Settings > Plugins > AGX Dynamics > Simulation.
The following Blueprint Visual Script graph demonstrates how to set a surface velocity on each contact point at On Impact and remove the contact in the following time step, when On Contact is called.
For more information on contact event listeners in AGX Dynamics see the Collision Events section of the AGX Dynamics user manual.