Table of Contents

Capsule with rigid body in F#

This code example demonstrates how to initialize a game, set up a basic 3D scene, create a 3D capsule entity, set its position, and add it to the scene using the extensions provided by the toolkit. The CreatePrimitive() 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.

Stride UI Example

View on GitHub.

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);
    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 the Game class, serving as the central part of the Stride engine for managing game loop, scenes, and entities.
  • let Start rootScene = Defines a function named Start that takes a Scene object named rootScene as an argument.
  • game.SetupBase3DScene() Sets up a basic 3D scene with a default camera, lighting, and skybox.
  • game.AddProfiler() |> ignore Adds a profiler to the game and discards the unneeded return value.
  • let firstBox = game.CreatePrimitive(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 <- rootScene Adds the entity to the rootScene.
  • [<EntryPoint>] Specifies that the following main function 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 the Start function as the start delegate.
  • 0 Indicates a successful program execution.