PhysicsBody PhysicsBody { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

Get the actual physics body that was created by this component. You should be careful, this can of course be null when the object is not enabled or the physics world is not available. It might also get deleted and re-created, so best use this to access, but don't store it.

Usage

Use the PhysicsBody property to access the underlying physics body associated with a Rigidbody component. This property is useful for interacting with the physics engine directly, such as applying forces or querying physical properties.

Be cautious when using this property, as the physics body may not always be available. It can be null if the component is disabled or if the physics world is not initialized. Additionally, the physics body might be recreated during the lifecycle of the component, so avoid storing a reference to it.

Example

// Example of accessing the PhysicsBody property
Rigidbody rigidbody = new Rigidbody();
PhysicsBody physicsBody = rigidbody.PhysicsBody;

if (physicsBody != null)
{
    // Perform operations with the physics body
    // For example, apply a force
    Vector3 force = new Vector3(0, 10, 0);
    physicsBody.ApplyForce(force);
}