checkpoint
This commit is contained in:
parent
3498fcc5aa
commit
cfe8a0acbd
2 changed files with 16 additions and 23 deletions
10
src/bike.rs
10
src/bike.rs
|
@ -74,7 +74,7 @@ fn spawn_bike(
|
|||
let body_collider =
|
||||
Collider::capsule_endpoints(0.5, Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8));
|
||||
|
||||
let _bike = commands
|
||||
commands
|
||||
.spawn((xform, Visibility::default()))
|
||||
.insert((
|
||||
Name::new("body"),
|
||||
|
@ -86,9 +86,7 @@ fn spawn_bike(
|
|||
CatControllerState::default(),
|
||||
ColliderDensity(0.6),
|
||||
AngularDamping(0.2),
|
||||
//LinearDamping(0.2),
|
||||
// LinearVelocity::ZERO,
|
||||
// AngularVelocity::ZERO,
|
||||
LinearDamping(0.1),
|
||||
ExternalForce::ZERO.with_persistence(false),
|
||||
ExternalTorque::ZERO.with_persistence(false),
|
||||
))
|
||||
|
@ -122,7 +120,7 @@ fn spawn_wheels(
|
|||
FRONT_ATTACH,
|
||||
Dir3::new_unchecked(front_rake),
|
||||
body,
|
||||
REST_DISTANCE + WHEEL_RADIUS,
|
||||
REST_DISTANCE,
|
||||
CyberWheel::Front,
|
||||
);
|
||||
wheel_mesh(
|
||||
|
@ -150,7 +148,7 @@ fn spawn_wheels(
|
|||
REAR_ATTACH,
|
||||
Dir3::new_unchecked(rear_rake),
|
||||
body,
|
||||
REST_DISTANCE + WHEEL_RADIUS,
|
||||
REST_DISTANCE,
|
||||
CyberWheel::Rear,
|
||||
);
|
||||
wheel_mesh(
|
||||
|
|
|
@ -164,22 +164,11 @@ mod systems {
|
|||
|
||||
pub(super) fn suspension(
|
||||
mut bike_body_query: Query<
|
||||
(
|
||||
&Transform,
|
||||
&LinearVelocity,
|
||||
&AngularVelocity,
|
||||
&mut ExternalForce,
|
||||
),
|
||||
(&Transform, &mut ExternalForce, RigidBodyQuery),
|
||||
With<CyberBikeBody>,
|
||||
>,
|
||||
mut wheel_mesh_query: Query<
|
||||
(
|
||||
&mut Transform,
|
||||
&mut WheelState,
|
||||
&GlobalTransform,
|
||||
&WheelConfig,
|
||||
&CyberWheel,
|
||||
),
|
||||
(&mut Transform, &mut WheelState, &WheelConfig, &CyberWheel),
|
||||
Without<CyberBikeBody>,
|
||||
>,
|
||||
caster_query: Query<(&RayCaster, &RayHits, &CyberWheel)>,
|
||||
|
@ -214,8 +203,13 @@ mod systems {
|
|||
}
|
||||
}
|
||||
}
|
||||
let (bike_xform, lin_vel, ang_vel, mut bike_forces) = bike_body_query.single_mut();
|
||||
for (mut xform, mut state, global_xform, config, wheel) in wheel_mesh_query.iter_mut() {
|
||||
|
||||
let Ok((bike_xform, mut bike_forces, rbq)) = bike_body_query.get_single_mut() else {
|
||||
bevy::log::warn!("Couldn't get body query");
|
||||
return;
|
||||
};
|
||||
|
||||
for (mut xform, mut state, 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),
|
||||
|
@ -244,14 +238,15 @@ mod systems {
|
|||
Color::linear_rgb(1., 0.5, 0.2),
|
||||
);
|
||||
|
||||
let _vel = rbq.velocity_at_point(hit_point);
|
||||
//bevy::log::info!("{_vel:?}");
|
||||
|
||||
bike_forces.apply_force_at_point(
|
||||
force,
|
||||
caster.global_origin(),
|
||||
bike_xform.translation,
|
||||
);
|
||||
//let vel = (global_xform.translation() - state.ppos) / dt;
|
||||
|
||||
state.ppos = global_xform.translation();
|
||||
let normal = hit.normal;
|
||||
let steering = match wheel {
|
||||
CyberWheel::Front => normal.cross(*bike_xform.back()) * yaw,
|
||||
|
|
Loading…
Reference in a new issue