PhysicsShape AddCapsuleShape( Vector3 center, Vector3 center2, float radius, bool rebuildMass )

robot_2Generated
code_blocksInput

Description

The AddCapsuleShape method adds a capsule-shaped physics shape to the PhysicsBody. A capsule is defined by two center points and a radius, forming a cylindrical shape with hemispherical ends. This method is useful for creating rounded, elongated shapes that can interact with other physics objects in the simulation.

Usage

To use the AddCapsuleShape method, you need to provide two center points, a radius, and a boolean indicating whether to rebuild the mass of the physics body. The centers define the line segment along which the capsule is aligned, and the radius defines the thickness of the capsule.

Parameters:

  • center: The starting center point of the capsule in world coordinates.
  • center2: The ending center point of the capsule in world coordinates.
  • radius: The radius of the capsule.
  • rebuildMass: A boolean indicating whether to recalculate the mass of the physics body after adding the shape. Set to true if the mass should be recalculated based on the new shape.

Example

// Example of adding a capsule shape to a PhysicsBody
PhysicsBody body = new PhysicsBody();
Vector3 startCenter = new Vector3(0, 0, 0);
Vector3 endCenter = new Vector3(0, 0, 2);
float radius = 0.5f;
bool rebuildMass = true;

PhysicsShape capsuleShape = body.AddCapsuleShape(startCenter, endCenter, radius, rebuildMass);