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.
Note
This example requires the additional NuGet package Stride.CommunityToolkit.Skyboxes
. Make sure to install it before running the code.
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 theGame
class, serving as the central part of the Stride engine for managing game loop, scenes, and entities.let Start rootScene =
Defines a function namedStart
that takes aScene
object namedrootScene
as 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() |> ignore
Adds 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 <- rootScene
Adds the entity to therootScene
.[<EntryPoint>]
Specifies that the followingmain
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 theStart
function as thestart
delegate.0
Indicates a successful program execution.