Move gravity management into RapierConfiguration resource.

Doesn't use external forces for gravity, which means that the wheels are now also affected by
gravity.
This commit is contained in:
Joe Ardent 2023-02-19 15:25:14 -08:00
parent 0f330283ee
commit d78e93b76a
2 changed files with 5 additions and 10 deletions

View file

@ -20,7 +20,6 @@ impl Plugin for CyberActionPlugin {
.register_type::<CatControllerSettings>()
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_startup_system(zero_gravity)
.add_system(surface_fix.label("surface_fix"))
.add_system(gravity.before("cat"))
.add_system(falling_cat.label("cat"))

View file

@ -18,19 +18,15 @@ use crate::{
const PITCH_SCALE: f32 = 0.2;
/// Disable gravity in Rapier.
pub(super) fn zero_gravity(mut config: ResMut<RapierConfiguration>) {
config.gravity = Vec3::ZERO;
}
/// The gravity vector points from the cyberbike to the center of the planet.
pub(super) fn gravity(
mut query: Query<(&Transform, &mut ExternalForce, &ReadMassProperties), With<CyberBikeBody>>,
mut query: Query<(&Transform, &mut ExternalForce), With<CyberBikeBody>>,
settings: Res<MovementSettings>,
mut rapier_config: ResMut<RapierConfiguration>,
) {
let (xform, mut forces, mprops) = query.single_mut();
let grav = xform.translation.normalize() * -settings.gravity * mprops.0.mass;
forces.force = grav;
let (xform, mut forces) = query.single_mut();
rapier_config.gravity = xform.translation.normalize() * -settings.gravity;
forces.force = Vec3::ZERO;
forces.torque = Vec3::ZERO;
}