Capsule with rigid body in F#
This code example demonstrates how to initialize a game, set up a basic 3D scene, add a skybox, create a 3D capsule entity, set its position, and add it to the scene using the extensions provided by the toolkit. The Create3DPrimitive() method, a part of the toolkit, automatically equips the capsule entity with a rigid body and a collider. This example serves as a simple starting point for building a game with Stride, leveraging the utilities provided by the toolkit to simplify common game development tasks.

View on GitHub.
open Stride.CommunityToolkit.Bepu;
open Stride.CommunityToolkit.Engine;
open Stride.CommunityToolkit.Skyboxes;
open Stride.CommunityToolkit.Rendering.ProceduralModels;
open Stride.Core.Mathematics;
open Stride.Engine;
let game = new Game()
let Start rootScene =
game.SetupBase3DScene()
game.AddSkybox() |> ignore
game.AddProfiler() |> ignore
let firstBox = game.Create3DPrimitive(PrimitiveModelType.Capsule, Bepu3DPhysicsOptions());
firstBox.Transform.Position <- new Vector3(0f, 2.5f, 0f)
firstBox.Scene <- rootScene
[<EntryPoint>]
let main argv =
game.Run(start = Start)
0
let game = new Game()Creates a new instance of theGameclass, serving as the central part of the Stride engine for managing game loop, scenes, and entities.let Start rootScene =Defines a function namedStartthat takes aSceneobject namedrootSceneas an argument.game.SetupBase3DScene()Sets up a basic 3D scene with a default camera, lighting.game.AddSkybox()Adds a skybox to the scene, providing a background image for the 3D environment.game.AddProfiler() |> ignoreAdds a profiler to the game and discards the unneeded return value.let firstBox = game.Create3DPrimitive(PrimitiveModelType.Capsule);Creates a new 3D capsule primitive entity.firstBox.Transform.Position <- new Vector3(0f, 2.5f, 0f)Sets the 3D position of the created entity.firstBox.Scene <- rootSceneAdds the entity to therootScene.[<EntryPoint>]Specifies that the followingmainfunction is the entry point of the application.let main argv =Defines the main function, which will be the entry point for the application.game.Run(start = Start)Initiates the game loop by passing theStartfunction as thestartdelegate.0Indicates a successful program execution.