use a raycast instead of shapecast
This commit is contained in:
parent
3e11c6439f
commit
ffbe45cf8e
2 changed files with 18 additions and 18 deletions
|
@ -187,7 +187,7 @@ fn wheel_caster(
|
||||||
rest_dist: Scalar,
|
rest_dist: Scalar,
|
||||||
wheel: CyberWheel,
|
wheel: CyberWheel,
|
||||||
) {
|
) {
|
||||||
let caster = ShapeCaster::new(collider, origin, Quat::IDENTITY, direction)
|
let caster = RayCaster::new(origin, direction)
|
||||||
.with_max_distance(rest_dist)
|
.with_max_distance(rest_dist)
|
||||||
.with_max_hits(1)
|
.with_max_hits(1)
|
||||||
.with_query_filter(SpatialQueryFilter::from_excluded_entities([parent]));
|
.with_query_filter(SpatialQueryFilter::from_excluded_entities([parent]));
|
||||||
|
|
|
@ -174,7 +174,7 @@ mod systems {
|
||||||
),
|
),
|
||||||
Without<CyberBikeBody>,
|
Without<CyberBikeBody>,
|
||||||
>,
|
>,
|
||||||
caster_query: Query<(&ShapeCaster, &ShapeHits, &CyberWheel)>,
|
caster_query: Query<(&RayCaster, &RayHits, &CyberWheel)>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
input: Res<InputState>,
|
input: Res<InputState>,
|
||||||
mut gizmos: Gizmos,
|
mut gizmos: Gizmos,
|
||||||
|
@ -188,11 +188,11 @@ mod systems {
|
||||||
let yaw = input.yaw * max_yaw;
|
let yaw = input.yaw * max_yaw;
|
||||||
let dt = time.delta().as_secs_f32();
|
let dt = time.delta().as_secs_f32();
|
||||||
|
|
||||||
let mut front_caster = &ShapeCaster::default();
|
let mut front_caster = &RayCaster::default();
|
||||||
let mut rear_caster = &ShapeCaster::default();
|
let mut rear_caster = &RayCaster::default();
|
||||||
|
|
||||||
let mut front_hits = &ShapeHits::default();
|
let mut front_hits = &RayHits::default();
|
||||||
let mut rear_hits = &ShapeHits::default();
|
let mut rear_hits = &RayHits::default();
|
||||||
|
|
||||||
for (caster, hits, wheel) in caster_query.iter() {
|
for (caster, hits, wheel) in caster_query.iter() {
|
||||||
match wheel {
|
match wheel {
|
||||||
|
@ -225,12 +225,16 @@ mod systems {
|
||||||
let mag = config.konstant * displacement - config.damping * damper_vel;
|
let mag = config.konstant * displacement - config.damping * damper_vel;
|
||||||
|
|
||||||
let mag = mag.max(0.0);
|
let mag = mag.max(0.0);
|
||||||
//let fdir = -caster.global_direction().as_vec3();
|
|
||||||
let fdir = hit.normal1;
|
let fdir = hit.normal;
|
||||||
let force = fdir * mag;
|
let force = fdir * mag;
|
||||||
//dbg!(fdir, force);
|
|
||||||
let p = hit.point1 + (hit.normal1 * config.radius);
|
let hit_point = caster.global_origin() + caster.global_direction() * dist;
|
||||||
gizmos.arrow(p, p + force, Color::linear_rgb(1., 0.5, 0.2));
|
gizmos.arrow(
|
||||||
|
hit_point,
|
||||||
|
hit_point + force,
|
||||||
|
Color::linear_rgb(1., 0.5, 0.2),
|
||||||
|
);
|
||||||
|
|
||||||
bike_forces.apply_force_at_point(
|
bike_forces.apply_force_at_point(
|
||||||
force,
|
force,
|
||||||
|
@ -240,7 +244,7 @@ mod systems {
|
||||||
//let vel = (global_xform.translation() - state.ppos) / dt;
|
//let vel = (global_xform.translation() - state.ppos) / dt;
|
||||||
|
|
||||||
state.ppos = global_xform.translation();
|
state.ppos = global_xform.translation();
|
||||||
let normal = hit.normal1;
|
let normal = hit.normal;
|
||||||
let steering = match wheel {
|
let steering = match wheel {
|
||||||
CyberWheel::Front => normal.cross(*bike_xform.back()) * yaw,
|
CyberWheel::Front => normal.cross(*bike_xform.back()) * yaw,
|
||||||
CyberWheel::Rear => Vec3::ZERO,
|
CyberWheel::Rear => Vec3::ZERO,
|
||||||
|
@ -248,12 +252,8 @@ mod systems {
|
||||||
};
|
};
|
||||||
let thrust = normal.cross(*bike_xform.right()) * thrust;
|
let thrust = normal.cross(*bike_xform.right()) * thrust;
|
||||||
let total = (thrust + steering) * dt;
|
let total = (thrust + steering) * dt;
|
||||||
bike_forces.apply_force_at_point(total, hit.point1, bike_xform.translation);
|
bike_forces.apply_force_at_point(total, hit_point, bike_xform.translation);
|
||||||
gizmos.arrow(
|
gizmos.arrow(hit_point, hit_point + total, Color::linear_rgb(1., 1., 0.2));
|
||||||
hit.point1,
|
|
||||||
hit.point1 + total,
|
|
||||||
Color::linear_rgb(1., 1., 0.2),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
xform.translation = config.attach + (caster.direction.as_vec3() * config.rest_dist);
|
xform.translation = config.attach + (caster.direction.as_vec3() * config.rest_dist);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue