Table of Contents

Class GameExtensions

Namespace
Stride.CommunityToolkit.Bullet
Assembly
Stride.CommunityToolkit.Bullet.dll

Provides extension methods for Game and IGame to simplify common scene setup and primitive creation tasks with Bullet physics.

public static class GameExtensions
Inheritance
GameExtensions

Methods

Add2DGround(Game, Bullet2DPhysicsOptions?)

Adds a 2D ground entity to the game using a cube primitive and Bullet static physics.

public static Entity Add2DGround(this Game game, Bullet2DPhysicsOptions? options = null)

Parameters

game Game

The game instance to which the ground entity will be added.

options Bullet2DPhysicsOptions

Optional 2D physics options used to configure the ground. When provided, Size is mapped to X/Y while Z uses Default2DGroundSize, and Position defaults to Default2DGroundPosition.

Returns

Entity

The newly created ground Entity added to the game.

Remarks

The resulting entity is created through 3D primitive generation and uses a StaticColliderComponent when no physics component is supplied in options.

Add3DGround(Game, Bullet3DPhysicsOptions?)

Adds a 3D ground entity to the game using a plane primitive and Bullet static physics.

public static Entity Add3DGround(this Game game, Bullet3DPhysicsOptions? options = null)

Parameters

game Game

The game instance to which the ground entity will be added.

options Bullet3DPhysicsOptions

Optional 3D physics options used to configure the ground. If null, defaults will be used.

Returns

Entity

The newly created ground Entity added to the game.

Remarks

When options is null, default options are created with a StaticColliderComponent. If EntityName is not provided, DefaultGroundName is used.

AddInfinite3DGround(Game, Bullet3DPhysicsOptions?)

Adds an infinite 3D ground entity to the game using an infinite plane primitive and Bullet static physics.

public static Entity AddInfinite3DGround(this Game game, Bullet3DPhysicsOptions? options = null)

Parameters

game Game

The game instance to which the infinite ground entity will be added.

options Bullet3DPhysicsOptions

Optional 3D physics options used to configure the ground. If null, defaults will be used.

Returns

Entity

The newly created infinite ground Entity added to the game.

Remarks

When options is null, default options are created with a StaticColliderComponent. If EntityName is not provided, DefaultGroundName is used. The visible part of the ground is defined by options, while the collider is infinite and extends beyond the visible ground.

Create2DPrimitive(IGame, Primitive2DModelType)

Creates a 2D primitive entity with a matching Bullet collider, using the default options.

public static Entity Create2DPrimitive(this IGame game, Primitive2DModelType type)

Parameters

game IGame

The game instance.

type Primitive2DModelType

The type of 2D primitive shape to create.

Returns

Entity

The newly created Entity with Bullet 2D physics attached.

Remarks

Exists so that game.Create2DPrimitive(type) resolves here rather than to the physics-free overload in Stride.CommunityToolkit.Engine, which has the same shape and is in scope whenever this package is. Both are applicable to that call; C# prefers the candidate that needs no default argument substituted, so this exact-arity overload wins, and F# applies the same preference. VB does not, so VB callers pass the options explicitly. Passing a Bullet2DPhysicsOptions reaches the overload below; passing a Primitive2DEntityOptions reaches the physics-free one.

Two things keep this working: a literal null for the options is still ambiguous, so use a typed null as the forwarding call here does; and the core method must not grow an exact-arity overload of its own, or the tie returns. This shadowing is a bridge until physics is selected once at setup, at which point these overloads go.

Create2DPrimitive(IGame, Primitive2DModelType, Bullet2DPhysicsOptions?)

Creates a 2D primitive entity and attaches Bullet 2D physics as defined by options.

public static Entity Create2DPrimitive(this IGame game, Primitive2DModelType type, Bullet2DPhysicsOptions? options = null)

Parameters

game IGame

The game instance.

type Primitive2DModelType

The type of 2D primitive shape to create.

options Bullet2DPhysicsOptions

Options for both the primitive geometry and physics. If null, defaults will be used.

Returns

Entity

The newly created Entity with Bullet 2D physics attached.

Create3DPrimitive(IGame, PrimitiveModelType)

Creates a 3D primitive entity with a matching Bullet collider, using the default options.

public static Entity Create3DPrimitive(this IGame game, PrimitiveModelType type)

Parameters

game IGame

The game instance.

type PrimitiveModelType

The type of 3D primitive shape to create.

Returns

Entity

The newly created Entity with Bullet 3D physics attached.

Remarks

Exists so that game.Create3DPrimitive(type) resolves here rather than to the physics-free overload in Stride.CommunityToolkit.Engine, which has the same shape and is in scope whenever this package is. Both are applicable to that call; C# prefers the candidate that needs no default argument substituted, so this exact-arity overload wins, and F# applies the same preference. VB does not, so VB callers pass the options explicitly. Passing a Bullet3DPhysicsOptions reaches the overload below; passing a Primitive3DEntityOptions reaches the physics-free one.

Two things keep this working: a literal null for the options is still ambiguous, so use a typed null as the forwarding call here does; and the core method must not grow an exact-arity overload of its own, or the tie returns. This shadowing is a bridge until physics is selected once at setup, at which point these overloads go.

Create3DPrimitive(IGame, PrimitiveModelType, Bullet3DPhysicsOptions?)

Creates a 3D primitive entity and attaches Bullet 3D physics as defined by options.

public static Entity Create3DPrimitive(this IGame game, PrimitiveModelType type, Bullet3DPhysicsOptions? options = null)

Parameters

game IGame

The game instance.

type PrimitiveModelType

The type of 3D primitive shape to create.

options Bullet3DPhysicsOptions

Options for both the primitive geometry and physics. If null, defaults will be used.

Returns

Entity

The newly created Entity with Bullet 3D physics attached.

SetupBase2DScene(Game)

Sets up a default 2D scene for the game, similar to creating an empty project through the editor.

public static void SetupBase2DScene(this Game game)

Parameters

game Game

The game instance to configure with the base 2D scene setup.

Remarks

This method performs the following setup operations in sequence:

  1. Configures base 2D scene settings.
  2. Adds a 2D camera controller.
  3. Adds a 2D ground entity with Bullet physics.

SetupBase3DScene(Game)

Sets up a default 3D scene for the game, similar to creating an empty project through the editor.

public static void SetupBase3DScene(this Game game)

Parameters

game Game

The game instance to configure with the base 3D scene setup.

Remarks

This method performs the following setup operations in sequence:

  1. Configures base 3D scene settings.
  2. Adds a 3D camera controller.
  3. Adds a 3D ground entity with Bullet physics.

ShowColliders(Game)

Enables the visualization of collider shapes in the game scene for debugging physics-related issues.

public static void ShowColliders(this Game game)

Parameters

game Game

The current game instance.

Remarks

This method activates the rendering of collider shapes within the physics simulation, helping to visually inspect and debug the positioning and behavior of colliders at runtime.