Description
The EnableTouchPersists
property of the PhysicsBody
class is used to set the EnableTouchPersists
property on all shapes associated with this physics body. This property determines whether persistent touch events are enabled for the physics shapes.
When set to true
, it indicates that at least one of the physics shapes has persistent touch events enabled. This can be useful for scenarios where continuous interaction with other physics objects is required, such as in games or simulations where objects need to maintain contact over time.
Usage
To use the EnableTouchPersists
property, simply set it on an instance of PhysicsBody
. This will propagate the setting to all associated physics shapes:
PhysicsBody myPhysicsBody = new PhysicsBody();
myPhysicsBody.EnableTouchPersists = true; // Enable persistent touch events
Checking the value of EnableTouchPersists
will return true
if any of the associated physics shapes have persistent touch events enabled:
bool isTouchPersistEnabled = myPhysicsBody.EnableTouchPersists;
Example
// Example of enabling persistent touch events on a PhysicsBody
PhysicsBody myPhysicsBody = new PhysicsBody();
// Enable persistent touch events for all shapes in this body
myPhysicsBody.EnableTouchPersists = true;
// Check if persistent touch events are enabled
bool isTouchPersistEnabled = myPhysicsBody.EnableTouchPersists;
// Output the result
// Note: Use a logging system instead of Console.WriteLine in Sandbox
// Log.Info($"Persistent Touch Enabled: {isTouchPersistEnabled}");