Skip to content

Commit

Permalink
Use local avian
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Sep 11, 2024
1 parent af5b719 commit f838d42
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 35 deletions.
8 changes: 1 addition & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ edition = "2021"
[dependencies]
# Bevy dependencies
bevy = { version = "0.14.2", features = ["wayland"] }
blenvy = { version = "0.1.0-alpha.1", git = "https://github.com/janhohenheim/blenvy", branch = "scheduling"}
avian3d = { git = "https://github.com/Jondolf/avian" }
avian_interpolation3d = { git = "https://github.com/janhohenheim/avian_interpolation", version = "0.1.0" }
blenvy = { version = "0.1.0-alpha.1", git = "https://github.com/janhohenheim/blenvy", branch = "initialization" }
avian3d = { path = "../avian/crates/avian3d" }
avian_interpolation3d = { path = "../avian_interpolation/crates/avian_interpolation3d" }
bevy-inspector-egui = { version = "0.25.2", optional = true }
leafwing-input-manager = { git = "https://github.com/Leafwing-Studios/leafwing_input_manager" }
bevy_dolly = "0.0.4"
bevy-tnua-avian3d = { version = "0.1.1", git = "https://github.com/janhohenheim/bevy-tnua", branch = "fix-minor-avian-stuff" }
bevy-tnua = { version = "0.19.0", git = "https://github.com/janhohenheim/bevy-tnua", branch = "fix-minor-avian-stuff"}
bevy-tnua-avian3d = { version = "0.1.1", path = "../bevy-tnua/avian3d" }
bevy-tnua = { version = "0.19.0", path = "../bevy-tnua/"}

# Generic dependencies
rand = "0.8"
Expand Down
30 changes: 29 additions & 1 deletion assets/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -3159,6 +3159,11 @@
"$ref": "#/$defs/bool"
}
},
"transform_to_collider_scale": {
"type": {
"$ref": "#/$defs/bool"
}
},
"transform_to_position": {
"type": {
"$ref": "#/$defs/bool"
Expand All @@ -3167,7 +3172,8 @@
},
"required": [
"position_to_transform",
"transform_to_position"
"transform_to_position",
"transform_to_collider_scale"
],
"short_name": "SyncConfig",
"type": "object",
Expand Down Expand Up @@ -16483,6 +16489,28 @@
"type": "string",
"typeInfo": "Enum"
},
"blenvy::save_load::Dynamic": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
"long_name": "blenvy::save_load::Dynamic",
"properties": {},
"required": [],
"short_name": "Dynamic",
"type": "object",
"typeInfo": "Struct"
},
"blenvy::save_load::StaticEntitiesRoot": {
"additionalProperties": false,
"isComponent": true,
"isResource": false,
"long_name": "blenvy::save_load::StaticEntitiesRoot",
"properties": {},
"required": [],
"short_name": "StaticEntitiesRoot",
"type": "object",
"typeInfo": "Struct"
},
"bool": {
"isComponent": false,
"isResource": false,
Expand Down
17 changes: 3 additions & 14 deletions src/hacks.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
use avian3d::prelude::*;
use bevy::prelude::*;
use avian3d::{prelude::*, sync::SyncConfig};
use bevy::{ecs::system::RunSystemOnce as _, prelude::*};

pub(super) fn plugin(app: &mut App) {
app.observe(fix_collider);
pub(super) fn plugin(_app: &mut App) {
}

fn fix_collider(
trigger: Trigger<OnAdd, Collider>,
mut q_floor: Query<(&GlobalTransform, &mut Collider)>,
) {
let Ok((transform, mut collider)) = q_floor.get_mut(trigger.entity()) else {
return;
};
let transform = transform.compute_transform();
collider.set_scale(transform.scale, 10);
}
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod system_set;
mod theme;
mod ui_camera;

use avian3d::PhysicsPlugins;
use avian3d::{prelude::SyncPlugin, sync::SyncConfig, PhysicsPlugins};
use avian_interpolation3d::prelude::*;
use bevy::{
asset::AssetMetaCheck,
Expand Down Expand Up @@ -79,9 +79,10 @@ impl Plugin for AppPlugin {
);

// Add third party plugins.
app.init_resource::<SyncConfig>();
app.add_plugins((
BlenvyPlugin::default(),
PhysicsPlugins::default(),
PhysicsPlugins::default().build().disable::<SyncPlugin>(),
AvianInterpolationPlugin::default(),
));

Expand Down
7 changes: 1 addition & 6 deletions src/player/camera/first_person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,14 @@ pub fn first_person_camera_bundle() -> impl Bundle {
}

fn follow_player(
time: Res<Time>,
mut q_camera: Query<&mut Transform, With<FirstPersonCamera>>,
q_player: Query<&Transform, (With<Player>, Without<FirstPersonCamera>)>,
) {
let dt = time.delta_seconds();
let Ok(player_transform) = q_player.get_single() else {
return;
};
let Ok(mut camera_transform) = q_camera.get_single_mut() else {
return;
};
let decay_rate = f32::ln(100.0);
let origin = &mut camera_transform.translation;
let target = player_transform.translation;
*origin = origin.lerp(target, 1.0 - f32::exp(-decay_rate * dt));
camera_transform.translation = player_transform.translation;
}

0 comments on commit f838d42

Please sign in to comment.