Replicates old feel with Rapier-native code.
This commit is contained in:
parent
5e4ef7d5de
commit
3cbdb522f2
3 changed files with 29 additions and 23 deletions
|
@ -10,8 +10,6 @@ use crate::{
|
|||
pub struct MovementSettings {
|
||||
pub sensitivity: f32,
|
||||
pub accel: f32,
|
||||
pub drag: f32,
|
||||
pub gravity: f32,
|
||||
}
|
||||
|
||||
impl Default for MovementSettings {
|
||||
|
@ -19,8 +17,6 @@ impl Default for MovementSettings {
|
|||
Self {
|
||||
sensitivity: 1.0,
|
||||
accel: 40.,
|
||||
drag: 0.0005,
|
||||
gravity: 10.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +33,12 @@ fn setup_colliders(
|
|||
};
|
||||
let pcollide = ColliderBundle {
|
||||
shape: ColliderShape::ball(PLANET_RADIUS).into(),
|
||||
material: ColliderMaterial {
|
||||
friction: 0.0,
|
||||
restitution: 0.3,
|
||||
..Default::default()
|
||||
}
|
||||
.into(),
|
||||
..Default::default()
|
||||
};
|
||||
commands
|
||||
|
@ -47,12 +49,24 @@ fn setup_colliders(
|
|||
let (bike, xform) = bike_query.single();
|
||||
let mut bbody = RigidBodyBundle::default();
|
||||
bbody.damping.angular_damping = 0.8;
|
||||
bbody.damping.linear_damping = 0.4;
|
||||
bbody.damping.linear_damping = 0.5;
|
||||
let isometry = Isometry::from_parts(xform.translation.into(), xform.rotation.into());
|
||||
bbody.position = isometry.into();
|
||||
// collider
|
||||
let shape = ColliderShape::capsule(
|
||||
Vec3::new(0.0, 0.0, -1.25).into(),
|
||||
Vec3::new(0.0, 0.0, 1.2).into(),
|
||||
0.4,
|
||||
);
|
||||
let bcollide = ColliderBundle {
|
||||
shape: ColliderShape::ball(1.1).into(),
|
||||
shape: shape.into(),
|
||||
mass_properties: ColliderMassProps::Density(0.3).into(),
|
||||
material: ColliderMaterial {
|
||||
friction: 0.0,
|
||||
restitution: 0.3,
|
||||
..Default::default()
|
||||
}
|
||||
.into(),
|
||||
..Default::default()
|
||||
};
|
||||
commands
|
||||
|
@ -63,30 +77,26 @@ fn setup_colliders(
|
|||
}
|
||||
|
||||
fn gravity(xform: Query<&Transform, With<CyberBike>>, mut config: ResMut<RapierConfiguration>) {
|
||||
let gravity = xform.single().translation.normalize() * -10.0;
|
||||
let gravity = xform.single().translation.normalize() * -8.0;
|
||||
config.gravity = gravity.into();
|
||||
}
|
||||
|
||||
fn falling_cat(
|
||||
time: Res<Time>,
|
||||
mut bike_query: Query<(&Transform, &mut RigidBodyForcesComponent), With<CyberBike>>,
|
||||
) {
|
||||
let dt = time.delta_seconds();
|
||||
|
||||
let (bike_xform, mut forces) = bike_query.single_mut();
|
||||
let up = bike_xform.translation.normalize();
|
||||
let cam_up = bike_xform.up();
|
||||
let cos = up.dot(cam_up);
|
||||
|
||||
let theta = cos.acos();
|
||||
let force = if !theta.is_normal() { 0.0 } else { theta * dt };
|
||||
let torque = cam_up.cross(up).normalize() * force * 50.0;
|
||||
let force_mag = if !theta.is_normal() { 0.0 } else { theta * 5.0 };
|
||||
let torque = cam_up.cross(up).normalize() * force_mag;
|
||||
|
||||
forces.torque = torque.into();
|
||||
}
|
||||
|
||||
fn update_forces(
|
||||
time: Res<Time>,
|
||||
settings: Res<MovementSettings>,
|
||||
input: Res<InputState>,
|
||||
mut query: Query<
|
||||
|
@ -98,19 +108,17 @@ fn update_forces(
|
|||
With<CyberBike>,
|
||||
>,
|
||||
) {
|
||||
let dt = time.delta_seconds();
|
||||
let (xform, mut forces, mut cmat) = query.single_mut();
|
||||
|
||||
// thrust
|
||||
let thrust: Vector3<f32> =
|
||||
(xform.forward() * input.throttle * dt * settings.accel * 500.0).into();
|
||||
let thrust: Vector3<f32> = (xform.forward() * input.throttle * settings.accel).into();
|
||||
forces.force += thrust;
|
||||
|
||||
// brake
|
||||
cmat.friction = if input.brake { 1.0 } else { 0.0 };
|
||||
cmat.friction = if input.brake { 2.0 } else { 0.0 };
|
||||
|
||||
// steering
|
||||
let torque: Vector3<f32> = (xform.up() * input.yaw * dt * settings.sensitivity * 500.0).into();
|
||||
let torque: Vector3<f32> = (xform.up() * input.yaw * settings.sensitivity).into();
|
||||
forces.torque += torque;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use bevy::prelude::*;
|
|||
|
||||
use crate::Label;
|
||||
|
||||
pub const PLANET_RADIUS: f32 = 360.0;
|
||||
pub const PLANET_RADIUS: f32 = 860.0;
|
||||
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS + 100.0;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
|
|
|
@ -11,10 +11,8 @@ use cyber_rider::{
|
|||
};
|
||||
|
||||
const MOVEMENT_SETTINGS: MovementSettings = MovementSettings {
|
||||
sensitivity: 0.3, // default: 1.0
|
||||
accel: 20.0, // default: 40.0
|
||||
drag: 0.0001, // default: 0.0005
|
||||
gravity: 10.0, // default: 10.0
|
||||
sensitivity: 4.0, // default: 1.0
|
||||
accel: 15.0, // default: 40.0
|
||||
};
|
||||
|
||||
fn main() {
|
||||
|
|
Loading…
Reference in a new issue