Crate bevy_rts_camera

Source
Expand description

Crates.io docs.rs Bevy tracking

Bevy RTS Camera

A screen recording showing camera movement

§Summary

Bevy RTS Camera provides an RTS-style camera for Bevy Engine, to get your game up and running quickly. Designed for simple use cases, and does not try to cover advanced requirements.

§Features:

  • Pan, zoom, and rotation
  • Automatically follows whatever you mark as ‘ground’
  • Smoothed movement
  • Customisable controls and other settings
  • Comes with optional controller, or you can control it yourself

§Default Controller

A default controller is included with these default controls:

  • Arrow Keys: pan
  • Mouse Wheel: zoom
  • Middle Mouse: rotate

You can also ‘edge pan’ by moving the mouse to the edge of the screen.

§Quick Start

Add the plugin:

.add_plugins(RtsCameraPlugin)

Add RtsCamera (this will automatically add a Camera3d but you can add it manually if necessary):

commands.spawn((
    RtsCamera::default(),
    RtsCameraControls::default(),  // Optional
));

Add Ground to your ground/terrain entities:

commands.spawn((
    PbrBundle {
        mesh: meshes.add(Plane3d::default().mesh().size(80.0, 80.0)),
        ..default()
    },
    Ground,
));

This will set up a camera at world origin with good defaults based on a roughly realistic scale (where an average human is 1.75 units tall).

Check out the advanced example to see the possible configuration options.

§Version Compatibility

bevybevy_rts_camera
0.150.9
0.140.8
0.130.1-0.7

§License

All code in this repository is dual-licensed under either:

at your option. This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem and there are very good reasons to include both.

Structs§

Ground
Marks an entity that should be treated as ‘ground’. The RTS camera will stay a certain distance (based on min/max height and zoom) above any meshes marked with this component (using a ray cast). You’ll likely want to mark all terrain entities, but not things like buildings, trees, or units.
RtsCamera
Marks a camera to be used as an RTS camera. Only one instance of this component should exist at any given moment. This does not include a controller. Add RtsCameraControls as well if you want.
RtsCameraControls
Optional camera controller. If you want to use an input manager, don’t use this and instead control the camera yourself by updating RtsCamera.target_focus and RtsCamera.target_zoom.
RtsCameraPlugin
Bevy plugin that provides RTS camera controls.
RtsCameraSystemSet
System set containing all the systems that control the RTS camera. If you want to control the camera manually in any way (e.g. snapping to a specific location), you should run that before this system set.