Expand description
§Bevy_adventure
A framework for building 3d adventure games in Bevy.
§Features
Interactivetrait is the backbone of the framework, allowing you to create powerful, dynamic objects in your world that can be interacted with and can affect other objects or global state.AdventureScenetrait exposes aPlugin-like interface for managingGLTFscenes and assigning components to entities (based onbevy_scene_hook)WorldStateresource, a stringly-typed storage for tracking progressionInventoryresource allows you to track held items and create recipes for combining them- Automatic camera animation and state management, Component-based interface
- Support for multiple scenes (built on top of
States) - Support for triggering animations and audio clips
§Examples
There is an elaborate example available at examples/main.rs.
Three scenes are included, with multiple objects that can be interacted with or picked up.
§Notes
§Save States
bevy_adventure intentionally omits implementing save state functionality, as different games will have different requirements.
If you want to implement this, here is what you need to keep track of:
CurrentSpotresource, which determines your current camera spot in the scene. When saving, save the name of theCameraSpotfrom this resource. When loading, create a newNextSpotinstance from the loaded name, and insert it withCommands.State<S>resource, which determines what scene is currently loadedInventoryresource, which tracks what items the player is holdingWorldStateresource, the global game state storage
You will also have to enable the serde feature to allow serialization and deserialization of these resources.
§Using WorldState
When you are building interactives, you have the ability to store information in the component itself or the WorldState.
The component should only hold temporary state information - like which drawer is open on a dresser or if an entity has been spawned.
If you want to store any other kind of information, it should be done in the WorldState resource. This is so other interactives in your scene can access this state (for example, you’d flip a switch and the lights would go out) and so you are storing state information in a single place.
§Creating scenes
When implementing the Scene trait, the scene method should return a path to a file that can be loaded with the AssetServer to create a Bevy Scene.
In practice this is a GLTF scene file, but any other format can be used as long as it creates a Bevy Scene when loaded.
When imported with bevy_adventure, Cameras are automatically converted to CameraSpots, and PointLights are configured to cast shadows.
The Scene trait’s spawn method is called for every Entity in the scene - you can use this to assign components and initialize behavior for objects in your scene.
The best way to do this is to match entity Names (from their names in the Scene), see the examples for an idea of how you should do this.
The only real requirement for your scene is that you create a special Camera with the name Camera_Main.
This is where your Camera will be positioned upon entering the Scene.
The app will panic if a scene is loaded without the Main Camera.
If you have issues matching objects by name, you might be matching the parent instead of the actual object you want to match. Adding a print statement inside of your Scene’s spawn method might help you figure out if the object is actually being found.
Note that when you are loading Scenes into Bevy, the ‘Transform Scale’ of each object is also loaded in. This could cause colliders to be the wrong size - you should ‘apply Scale’ before exporting.
Object origin is also used loaded in - this could cause misaligned colliders if your object’s origin doesn’t match the center of your object.
Blender is a good choice to create GLTF scenes, but you must make sure you configure the export settings correctly:
- Under
Include, checkCustom Properties,Cameras, andPunctual Lights. - Under
Transform, uncheckY+ Up
§TODO
- Save state example
§License
bevy_adventure is dual-licensed under MIT and Apache-2.0.
§Compatibility
NOTE: We do not track Bevy main.
| Bevy Version | Crate Version |
|---|---|
0.12 | 0.6 |
0.10 | 0.5 |
0.9 | 0.1, 0.2, 0.3, 0.4 |
Modules§
- prelude
- Prelude: convenient import for all the user-facing APIs provided by the crate
Structs§
- Adventure
Plugin - The main plugin that must be added to your app with
App::add_plugin. - Animation
Server SystemParamfor registering named Animations.- Audio
Server SystemParamfor registeringAudioSourceclips by path.- Back
ToSpot - A component for a
CameraSpotthat defines what spot you will go back when at that spot. - Back
ToState - A component for a
CameraSpotthat defines what state you will go back when at that spot. - Camera
Spot - A
CameraSpot- a location the Camera might be at in the scene. - Camera
Spots SystemParamfor retrievingCameraSpotsfor entities or from names.- Commands
Ext SystemParamthat acts as an extension toCommandsfor working with named entities.- Current
Spot - Resource that specifies what
CameraSpotthe player is at. - Cursor
- A resource that stores the current position of the Cursor.
- Description
- A preset
Interactivethat displays a message when interacted with. - Dragging
Item - A resource that stores which items are being dragged, if any.
- Hovering
- The entity that the cursor is currently hovering over, if any.
- Ignores
- A component for a
CameraSpotthat defines what objects are ignored when at that spot. - Inventory
- A resource that stores the player’s current inventory.
- Item
- An item.
- ItemRef
- A reference to an item, passed into an Interactive.
- MoveTo
- A preset
Interactivethat moves to aCameraSpotwhen interacted with. - NewMessage
- An event that triggers whenever an
Action::Messageis executed. - Next
Spot - Insert this resource to determine what
CameraSpotthe Camera will move to next. - Portal
- A preset
Interactivethat changes the current state when interacted with. - Prop
- A preset
Interactivethat does nothing when interacted with. - Recipes
- A resource that stores all registered item combinations.
- Simple
- An
Interactivethat just runs the given actions when interacted with. - Skip
Animation - Insert this resource at the same time as
NextSpotto skip animation. - Trigger
- A preset
Interactivethat does nothing when interacted with. - World
State - Stringly-typed key value store for tracking game progression.
Enums§
- Action
- An enum of possible actions an Interactive might take after being interacted with in some way.
- Message
- A struct that represents a message that should be displayed.
Constants§
- MAIN_
CAMERA - The main camera spot in a scene is always named
Camera_Main.
Traits§
- Adventure
Scene - Trait that provides a
Plugin-like interface for defining game scenes. - AppScene
State Ext - Extension trait that adds Scene-related methods to Bevy’s
App. - Commands
Actions Ext - Extension trait that adds Action-related methods to Bevy’s
EntityCommands. - Interactive
- Trait that allows you to define behavior for an object in a Scene.
Functions§
- invalid_
item_ used - Helper function that returns an action with an
InvalidItemUsedmessage.