Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
[package]
name = "bevy_third_person_camera"
version = "0.3.0"
edition = "2021"
version = "0.4.2"
authors = ["Oleks Pickle <22867443+olekspickle@users.noreply.github.com>"]
edition = "2024"
description = "A third person camera written for Bevy"
keywords = ["bevy", "camera", "orbit", "gamedev"]
categories = ["game-development"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/AndrewCS149/bevy_third_person_camera"
homepage = "https://github.com/AndrewCS149/bevy_third_person_camera"
repository = "https://github.com/olekspickle/bevy_third_person_camera"
homepage = "https://github.com/olekspickle/bevy_third_person_camera"
readme = "README.md"
exclude = ["assets/*", "migrationGuides/*"]
exclude = ["assets/*"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


[dependencies]
bevy = { version = "0.16", default-features = false, features = ["bevy_window"] }
bevy = { version = "0.18", default-features = false, features = ["bevy_window", "gamepad"] }
avian3d = "0.6.0-rc.1"
bevy_unified_input = "0.2"

[dev-dependencies]
bevy = "0.16"
bevy_rapier3d = "0.29"
bevy = "0.18"
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# v0.3.0

- Add semantic versioning

Contributors:
- https://github.com/Leinnan

# v0.2.1

- Update to Bevy v0.16

# v0.2.0

## <ins>!Breaking Changes!<ins>
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

## Getting Started

Add the **bevy_third_person_camera** crate:
Add the **bevy_third_person_camera** crate:

```
cargo add bevy_third_person_camera
Expand All @@ -24,18 +24,18 @@ Import the **bevy_third_person_camera** crate:
use bevy_third_person_camera::*;
```

Add the **ThirdPersonCameraPlugin**:
Add the **ThirdPersonCameraPlugin**:

```rust
.add_plugins(ThirdPersonCameraPlugin)
```

Add the **ThirdPersonCamera** component to the camera entity:
Add the **ThirdPersonCamera** component to the camera entity:

```rust
commands.spawn((
Camera3d::default(),
ThirdPersonCamera::default(),
ThirdPersonCamera::default(),
));
```

Expand All @@ -52,13 +52,13 @@ commands.spawn((
));
```

That's it!
That's it!

## Examples

- default
- custom
- physics # not working at the moment. Waiting for bevy_rapier3d to support Bevy v0.15.0
- physics

```
cargo run --example <example name>
Expand All @@ -68,7 +68,7 @@ cargo run --example <example name>

### Offset

The `offset` will 'offset' the x and y values of the camera respectively. Offset is disabled by default. Turn on with `offset_enabled: true`
The `offset` will 'offset' the x and y values of the camera respectively. Offset is disabled by default. Turn on with `offset_enabled: true`

```rust
offset_enabled: true,
Expand Down Expand Up @@ -109,7 +109,7 @@ Orbiting is enabled by default. However, you can set the `mouse_orbit_button_ena

## Custom Settings

Most settings can be overridden:
Most settings can be overridden:

```rust
let gamepad = Gamepad::new(0);
Expand Down Expand Up @@ -170,6 +170,8 @@ When using third party physics engines such as bevy rapier 3d or avian 3d, you s

| bevy | bevy_third_person_camera |
| ---- | ------------------------ |
| 0.18 | 0.4 |
| 0.17 | 0.3 |
| 0.16 | 0.2.1 - 0.3 |
| 0.15 | 0.2.0 |
| 0.14 | 0.1.11 - 0.1.14 |
Expand Down
45 changes: 18 additions & 27 deletions examples/physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,42 @@ Example displaying the integration with a third party physics engine. In this ca
The key is to run the CameraSyncSet AFTER the PhysicsSet, see line 19.
*/

use avian3d::prelude::*;
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use bevy_third_person_camera::*;

fn main() {
App::new()
.add_plugins((
DefaultPlugins,
ThirdPersonCameraPlugin,
RapierPhysicsPlugin::<NoUserData>::default(),
))
.add_plugins((DefaultPlugins, ThirdPersonCameraPlugin))
.add_systems(Startup, (spawn_player, spawn_world, spawn_camera))
.add_systems(Update, player_movement_keyboard)
.configure_sets(PostUpdate, CameraSyncSet.after(PhysicsSet::StepSimulation)) // DO THIS!
.configure_sets(
PostUpdate,
CameraSyncSet.after(PhysicsSystems::StepSimulation),
) // DO THIS!
.run();
}

#[derive(Component)]
struct Player;

#[derive(Component)]
struct Speed(f32);
struct Player {
pub speed: f32,
}

fn spawn_player(mut commands: Commands, assets: Res<AssetServer>) {
let player = (
SceneRoot(assets.load("Player.gltf#Scene0")),
Transform::from_xyz(0.0, 1.0, 0.0),
Collider::cuboid(0.25, 0.5, 0.25),
RigidBody::Dynamic,
Damping {
linear_damping: 5.0,
..default()
},
ExternalImpulse::default(),
Player,
Player { speed: 4.0 },
LinearVelocity::ZERO,
ThirdPersonCameraTarget,
Speed(4.0),
);
commands.spawn(player);
}

fn spawn_camera(mut commands: Commands) {
let camera = (
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
ThirdPersonCamera {
Expand All @@ -61,14 +54,12 @@ fn spawn_camera(mut commands: Commands) {
zoom: Zoom::new(1.5, 3.0), // default
..default()
},
);
commands.spawn(camera);
));
}

fn spawn_world(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,

mut materials: ResMut<Assets<StandardMaterial>>,
) {
let floor: (Mesh3d, MeshMaterial3d<StandardMaterial>, Collider) = (
Expand All @@ -92,13 +83,13 @@ fn spawn_world(
fn player_movement_keyboard(
time: Res<Time>,
keys: Res<ButtonInput<KeyCode>>,
mut player_q: Query<(&mut ExternalImpulse, &mut Transform, &Speed), With<Player>>,
mut player_q: Query<(&mut LinearVelocity, &mut Transform, &mut Player), With<Player>>,
cam_q: Query<&Transform, (With<Camera3d>, Without<Player>)>,
) {
for (mut ext_impulse, mut player_transform, player_speed) in player_q.iter_mut() {
for (mut linear_velocity, mut player_transform, player) in player_q.iter_mut() {
let cam = match cam_q.single() {
Ok(c) => c,
Err(e) => Err(format!("Error retrieving camera: {}", e)).unwrap(),
Err(e) => panic!("Error retrieving camera: {}", e),
};

let mut direction = Vec3::ZERO;
Expand All @@ -124,8 +115,8 @@ fn player_movement_keyboard(
}

direction.y = 0.0;
let movement = direction.normalize_or_zero() * player_speed.0 * time.delta_secs();
ext_impulse.impulse += movement;
let movement = direction.normalize_or_zero() * player.speed * time.delta_secs();
linear_velocity.0 += movement;

// rotate player to face direction he is currently moving
if direction.length_squared() > 0.0 {
Expand Down
Binary file removed migrationGuides/imgs/0.1.10-1.png
Binary file not shown.
7 changes: 0 additions & 7 deletions migrationGuides/v0.1.10-v0.1.11.md

This file was deleted.

3 changes: 0 additions & 3 deletions migrationGuides/v0.1.14-v0.2.0.md

This file was deleted.

13 changes: 0 additions & 13 deletions migrationGuides/v0.1.9-v0.1.10.md

This file was deleted.

22 changes: 8 additions & 14 deletions src/gamepad.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::f32::consts::PI;

use crate::{zoom_condition, ThirdPersonCamera};
use crate::{ThirdPersonCamera, zoom_condition};
use bevy::{prelude::*, window::PrimaryWindow};
use std::f32::consts::PI;

pub struct GamePadPlugin;

Expand Down Expand Up @@ -73,26 +72,21 @@ pub fn orbit_gamepad(
if cam.mouse_orbit_button_enabled && !gamepad.pressed(cam.gamepad_settings.mouse_orbit_button) {
return;
}

let x_axis = gamepad.right_stick().x;
let y_axis = gamepad.right_stick().y;
let (x, y) = (gamepad.right_stick().x, gamepad.right_stick().y);

let deadzone = 0.5;
let mut rotation = Vec2::ZERO;
let (x, y) = (x_axis, y_axis);
if x.abs() > deadzone || y.abs() > deadzone {
rotation = Vec2::new(x, y);
}

if rotation.length_squared() > 0.0 {
let window = window_q.single().unwrap();
let delta_x = {
let delta = rotation.x / window.width()
* std::f32::consts::PI
* 2.0
* cam.gamepad_settings.sensitivity.x;
delta
};
let delta_x = rotation.x / window.width()
* std::f32::consts::PI
* 2.0
* cam.gamepad_settings.sensitivity.x;

let delta_y = -rotation.y / window.height() * PI * cam.gamepad_settings.sensitivity.y;
let yaw = Quat::from_rotation_y(-delta_x);
let pitch = Quat::from_rotation_x(-delta_y);
Expand Down
Loading