Thanks to visit codestin.com
Credit goes to github.com

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
23 changes: 5 additions & 18 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tracing = "0.1.37"
puffin = { version = "0.17.0", features = ["web"] }
puffin_egui = "0.23.0"
petgraph = "0.6.4"
rapier2d = { version = "0.17.2", features = ["debug-render", "enhanced-determinism"] }
rapier2d = { git = "https://github.com/MaxCWhitehead/rapier", branch = "fix-dynamic-change", features = ["debug-render", "enhanced-determinism"] }
indexmap = "2.0.0"
serde = { version = "1.0.188", features = ["derive"] }
shiftnanigans = "0.3.3"
Expand Down
6 changes: 4 additions & 2 deletions src/core/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ impl<'a> rapier::DebugRenderBackend for RapierDebugBackend<'a> {
rapier::DebugRenderObject::Collider(_, collider) => collider.is_enabled(),
rapier::DebugRenderObject::ImpulseJoint(_, _) => true,
rapier::DebugRenderObject::MultibodyJoint(_, _, _) => true,
rapier::DebugRenderObject::Other => true,
rapier::DebugRenderObject::ColliderAabb(_, _, _) => true,
rapier::DebugRenderObject::ContactPair(_, _, _) => true,
};
if render {
self.points.push(vec2(a.x, a.y));
Expand Down Expand Up @@ -94,14 +95,15 @@ fn debug_render_colliders(
settings: ResInit<DebugSettings>,
mut collision_world: CollisionWorld,
transforms: Comp<Transform>,
mut dynamic_bodies: CompMut<DynamicBody>,
mut paths: CompMut<Path2d>,
mut debug_context: ResMutInit<RapierDebugContext>,
) {
if settings.show_kinematic_colliders {
// TODO: It's unfortunate that we are doing an extra sync here, just for debug rendering. We
// should try find a way to avoid this. Without this, the collider body positions will be
// out of sync when they are rendered.
collision_world.update(&transforms);
collision_world.sync_bodies(&transforms, &mut dynamic_bodies);

let mut points = Vec::new();
let mut line_breaks = Vec::new();
Expand Down
32 changes: 28 additions & 4 deletions src/core/physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
use crate::prelude::*;

pub use collisions::{
Actor, Collider, ColliderShape, CollisionWorld, RapierContext, RapierUserData, Solid,
TileCollisionKind,
Actor, Collider, ColliderShape, CollisionWorld, PhysicsParams, RapierContext, RapierUserData,
Solid, TileCollisionKind,
};

use super::utils::Rect;
pub use rapier2d::prelude as rapier;

pub mod collisions;
pub mod dynamic_body;

pub use dynamic_body::*;

/// For now kinematic mode is globally position based.
pub static KINEMATIC_MODE: rapier::RigidBodyType = rapier::RigidBodyType::KinematicPositionBased;

#[derive(Debug, Clone, Copy)]
enum PhysicsStage {
Expand Down Expand Up @@ -145,6 +152,7 @@ fn update_kinematic_bodies(
meta: Root<GameMeta>,
entities: Res<Entities>,
mut bodies: CompMut<KinematicBody>,
mut dynamic_bodies: CompMut<DynamicBody>,
mut collision_world: CollisionWorld,
mut transforms: CompMut<Transform>,
time: Res<Time>,
Expand All @@ -153,15 +161,31 @@ fn update_kinematic_bodies(

let time_factor = time.delta().as_secs_f32();

collision_world.update(&transforms);
for (entity, body) in entities.iter_with(&mut bodies) {
let global_gravity = meta.core.physics.gravity;
collision_world.update(
time_factor,
PhysicsParams {
gravity: global_gravity,
terminal_velocity: Some(meta.core.physics.terminal_velocity),
},
&mut transforms,
&mut dynamic_bodies,
);
for (entity, (body, dynamic_body)) in
entities.iter_with((&mut bodies, &mut OptionalMut(&mut dynamic_bodies)))
{
if body.is_deactivated {
collision_world.colliders.get_mut(entity).unwrap().disabled = true;
continue;
} else {
collision_world.colliders.get_mut(entity).unwrap().disabled = false;
}

if let Some(dynamic_body) = dynamic_body {
if dynamic_body.is_dynamic {
continue;
}
}
// has the body moved since last call to update_kinematic_bodies?
let has_moved = {
let transform = transforms.get(entity).copied().unwrap();
Expand Down
Loading