Verse Library verse

01 Fragment

Programmatically creates and attaches a 3D robot entity to the simulation scene graph.

verse-library/understanding-the-scene-graph-entities-and-components-in-verse/01-fragment.verse

# We define a new type of object called "HelloBot"
HelloBot: entity = entity{
    # We add a mesh component to give it a shape
    MeshComponent: mesh_component = mesh_component{
        # This sets the shape to a simple box
        Mesh := StaticMesh'Engine/BasicShapes/Box.StaticMesh'
    },
    # We add a transform component to set its position
    TransformComponent: transform_component = transform_component{
        # This moves it slightly to the right so you can see it
        Translation := vector3{
            Left := 100.0,
            Up := 50.0,
            Forward := 0.0
        }
    }
}

# This function runs when the game starts
OnBegin<override>()<suspends>: void = (
    # We find the main trunk of our scene graph
    if (SimEntity := Entity.GetSimulationEntity[]):
        # We add our new HelloBot to the trunk
        # This makes it appear in the game!
        SimEntity.AddEntities(array{HelloBot})
)

Comments

    Sign in to vote, comment, or suggest an edit. Sign in