checkpoint
This commit is contained in:
parent
5852df32f7
commit
8978a25965
2 changed files with 14 additions and 7 deletions
|
@ -22,11 +22,11 @@ pub enum CyberWheel {
|
|||
|
||||
#[derive(Component, Clone, Copy, Debug, Reflect, Default)]
|
||||
#[reflect(Component)]
|
||||
#[require(LinearVelocity, RigidBody(|| RigidBody::Kinematic))]
|
||||
pub struct WheelState {
|
||||
pub displacement: Scalar,
|
||||
pub sliding: bool,
|
||||
pub grounded: bool,
|
||||
pub ppos: Vec3,
|
||||
}
|
||||
|
||||
#[derive(Component, Clone, Copy, Debug, Reflect)]
|
||||
|
@ -126,7 +126,7 @@ fn spawn_wheels(
|
|||
&mut materials,
|
||||
front_wheel_pos,
|
||||
mesh.clone(),
|
||||
WheelConfig::new(FRONT_ATTACH, REST_DISTANCE, 1200., -160., 0.5),
|
||||
WheelConfig::new(FRONT_ATTACH, REST_DISTANCE, 800., -160., 0.5),
|
||||
CyberWheel::Front,
|
||||
);
|
||||
|
||||
|
@ -148,7 +148,7 @@ fn spawn_wheels(
|
|||
&mut materials,
|
||||
rear_wheel_pos,
|
||||
mesh,
|
||||
WheelConfig::new(REAR_ATTACH, REST_DISTANCE, 1200., -160., 0.5),
|
||||
WheelConfig::new(REAR_ATTACH, REST_DISTANCE, 800., -160., 0.5),
|
||||
CyberWheel::Rear,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -163,8 +163,8 @@ mod systems {
|
|||
(
|
||||
&mut Transform,
|
||||
&mut WheelState,
|
||||
&GlobalTransform,
|
||||
&WheelConfig,
|
||||
&LinearVelocity,
|
||||
&CyberWheel,
|
||||
),
|
||||
Without<CyberBikeBody>,
|
||||
|
@ -202,21 +202,23 @@ mod systems {
|
|||
}
|
||||
}
|
||||
let (bike_xform, mut bike_forces) = bike_body_query.single_mut();
|
||||
for (mut xform, mut state, config, velocity, wheel) in wheel_mesh_query.iter_mut() {
|
||||
for (mut xform, mut state, global_xform, config, wheel) in wheel_mesh_query.iter_mut() {
|
||||
let (caster, hits) = match wheel {
|
||||
CyberWheel::Front => (front_caster, front_hits),
|
||||
CyberWheel::Rear => (rear_caster, rear_hits),
|
||||
};
|
||||
|
||||
let prev = &mut state.displacement;
|
||||
for hit in hits.iter() {
|
||||
if let Some(hit) = hits.iter().next() {
|
||||
let force = suspension_force(caster, hit, config, prev, dt, &mut xform);
|
||||
bike_forces.apply_force_at_point(
|
||||
force,
|
||||
caster.global_origin(),
|
||||
bike_xform.translation,
|
||||
);
|
||||
dbg!(velocity);
|
||||
let vel = (global_xform.translation() - state.ppos) / dt;
|
||||
dbg!(vel);
|
||||
state.ppos = global_xform.translation();
|
||||
let normal = hit.normal1;
|
||||
let steering = match wheel {
|
||||
CyberWheel::Front => normal.cross(*bike_xform.back()) * yaw,
|
||||
|
@ -230,6 +232,8 @@ mod systems {
|
|||
hit.point1 + total,
|
||||
Color::linear_rgb(1., 1., 0.2),
|
||||
);
|
||||
} else {
|
||||
xform.translation = config.attach + (caster.direction.as_vec3() * config.rest_dist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -274,6 +278,9 @@ impl Plugin for CyberPhysicsPlugin {
|
|||
.register_type::<CyberLean>()
|
||||
.add_plugins((PhysicsPlugins::default(), PhysicsDebugPlugin::default()))
|
||||
.insert_resource(SubstepCount(12))
|
||||
.add_systems(Startup, |mut gravity: ResMut<Gravity>| {
|
||||
gravity.0 *= 0.02;
|
||||
})
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
(calculate_lean, apply_lean, suspension).chain(),
|
||||
|
|
Loading…
Reference in a new issue