Table of Contents

Capsule with rigid body in Visual Basic

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.

Stride UI Example

View on GitHub.

Imports Stride.CommunityToolkit.Engine
Imports Stride.CommunityToolkit.Rendering.ProceduralModels
Imports Stride.CommunityToolkit.Skyboxes
Imports Stride.Core.Mathematics
Imports Stride.Engine
Imports GameExtensions = Stride.CommunityToolkit.Engine.GameExtensions

Module Program
    Private game As New Game()

    Sub Main()
        GameExtensions.Run(game, Nothing, AddressOf StartGame)
    End Sub

    Private Sub StartGame(rootScene As Scene)
        game.SetupBase3DScene()
        game.AddSkybox()
        game.AddProfiler()

        Dim entity = game.Create3DPrimitive(PrimitiveModelType.Capsule)
        entity.Transform.Position = New Vector3(0, 8, 0)
        entity.Scene = rootScene
    End Sub
End Module
  • Private game As New Game() This line of code creates a new instance of the Game class. The Game class is central to the Stride engine, managing the overall game loop, scenes, and updates to the entities.
  • GameExtensions.Run(game, Nothing, AddressOf StartGame) This line initiates the game loop. The Run method, from GameExtensions, is responsible for starting the game and it takes a reference to the StartGame method as a parameter. This method is called once when the game starts. The Nothing argument here is for an optional parameter that is not being used in this case.
  • game.SetupBase3DScene() This line sets up a basic 3D scene. It's a helper method provided to quickly set up a scene with a default camera, lighting.
  • game.AddSkybox() This line adds a skybox to the scene. A skybox is a cube that surrounds the entire scene and is textured with an image to create the illusion of a sky.
  • game.AddProfiler() This line adds a profiler to the game.
  • Dim entity = game.Create3DPrimitive(PrimitiveModelType.Capsule) Here, a new entity is created in the form of a 3D capsule primitive. The Create3DPrimitive method is a helper method provided to create basic 3D shapes.
  • entity.Transform.Position = New Vector3(0, 8, 0) This line sets the position of the created entity in the 3D space. The Position property of the Transform component determines the location of the entity.
  • entity.Scene = rootScene Finally, the entity is added to the rootScene. The Scene property of an entity determines which scene it belongs to.