Add drag, re-enable CCD for bike.

This commit is contained in:
Joe Ardent 2022-02-24 23:20:29 -08:00
parent 83af546e63
commit 79ddc3f951
2 changed files with 24 additions and 22 deletions

View File

@ -55,13 +55,6 @@ fn setup_colliders(
let pbody = RigidBodyBundle {
body_type: RigidBodyType::Static.into(),
// ccd: RigidBodyCcd {
// ccd_enabled: true,
// ccd_max_dist: PLANET_RADIUS * 1.1,
// ccd_thickness: 0.1,
// ..Default::default()
// }
// .into(),
..Default::default()
};
let pcollide = ColliderBundle {
@ -87,21 +80,18 @@ fn setup_colliders(
fn setup_bike_collider(bike: Entity, xform: &Transform, commands: &mut Commands) {
let mut bbody = RigidBodyBundle::default();
bbody.damping.angular_damping = 0.8;
bbody.damping.linear_damping = 0.4;
bbody.forces = RigidBodyForces {
torque: Vec3::ZERO.into(),
bbody.damping.linear_damping = 0.1;
bbody.ccd = RigidBodyCcd {
ccd_enabled: true,
ccd_thickness: 0.7,
ccd_max_dist: 1.5,
..Default::default()
}
.into();
// bbody.ccd = RigidBodyCcd {
// ccd_enabled: false,
// ccd_max_dist: 2.4,
// ..Default::default()
// }
// .into();
let isometry = Isometry::from_parts(xform.translation.into(), xform.rotation.into());
bbody.position = isometry.into();
// collider
@ -174,6 +164,17 @@ fn update_forces(
forces.torque += torque;
}
fn drag(
mut query: Query<(&RigidBodyVelocityComponent, &mut RigidBodyForcesComponent), With<CyberBike>>,
) {
let (vels, mut forces) = query.single_mut();
if let Some(vel) = vels.linvel.try_normalize(0.001) {
let v2 = vels.linvel.magnitude_squared();
forces.force -= vel * v2 * 0.002;
}
}
pub struct CyberActionPlugin;
impl Plugin for CyberActionPlugin {
fn build(&self, app: &mut App) {
@ -185,6 +186,7 @@ impl Plugin for CyberActionPlugin {
)
.add_system(gravity)
.add_system(falling_cat.label("cat"))
.add_system(update_forces.after("cat"));
.add_system(drag.label("drag").after("uforces"))
.add_system(update_forces.label("uforces").after("cat"));
}
}

View File

@ -3,13 +3,13 @@ use bevy::{
render::mesh::Indices,
};
use hexasphere::shapes::IcoSphere;
use noise::{HybridMulti, NoiseFn, Perlin};
use noise::{HybridMulti, NoiseFn, Simplex};
use wgpu::PrimitiveTopology;
use crate::Label;
pub const PLANET_RADIUS: f32 = 5000.0;
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.095;
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.015;
#[derive(Component, Debug)]
pub struct CyberBike;
@ -25,7 +25,7 @@ fn spawn_giant_sphere(
let color = Color::DARK_GRAY;
let isphere = shape::Icosphere {
radius: PLANET_RADIUS,
subdivisions: 40,
subdivisions: 64,
};
let pmesh = gen_planet(isphere);
@ -89,7 +89,7 @@ fn gen_planet(sphere: Icosphere) -> Mesh {
// TODO: use displaced points for normals by replacing raw_points with
// noise-displaced points.
let noise = HybridMulti::<Perlin>::default();
let noise = HybridMulti::<Simplex>::default();
let raw_points = generated
.raw_points()