ModelBuilder AddCollisionHull( Vector3[] vertices, System.Nullable<Vector3> center, System.Nullable<Rotation> rotation )

book_4_sparkGenerated
code_blocksInput

Description

The AddCollisionHull method is part of the ModelBuilder class in the Sandbox API. This method allows you to add a collision hull to a model being constructed. A collision hull is a simplified representation of the model's shape used for collision detection.

Usage

To use the AddCollisionHull method, you need to provide an array of vertices that define the shape of the collision hull. Optionally, you can specify a center point and a rotation for the hull. If the center or rotation is not specified, the default values will be used.

The method returns the ModelBuilder instance, allowing for method chaining.

Example

// Example of using AddCollisionHull
var modelBuilder = new ModelBuilder();

// Define vertices for the collision hull
Vector3[] vertices = new Vector3[]
{
    new Vector3(0, 0, 0),
    new Vector3(1, 0, 0),
    new Vector3(0, 1, 0),
    new Vector3(0, 0, 1)
};

// Add a collision hull with specified vertices
modelBuilder.AddCollisionHull(vertices);

// Optionally, specify a center and rotation
Vector3? center = new Vector3(0.5f, 0.5f, 0.5f);
Rotation? rotation = new Rotation(0, 0, 0);
modelBuilder.AddCollisionHull(vertices, center, rotation);

// Continue building the model
var model = modelBuilder.Create();