checkpoint, no normal force yet
This commit is contained in:
parent
e358830c5f
commit
18766a3d5b
1 changed files with 23 additions and 11 deletions
|
@ -1,7 +1,7 @@
|
||||||
use std::f32::consts::{FRAC_PI_3, FRAC_PI_4};
|
use std::f32::consts::{FRAC_PI_3, FRAC_PI_4};
|
||||||
|
|
||||||
use bevy::prelude::{
|
use bevy::prelude::{
|
||||||
Commands, Entity, Local, Quat, Query, Res, ResMut, Time, Transform, Vec3, With, Without,
|
info, Commands, Entity, Local, Quat, Query, Res, ResMut, Time, Transform, Vec3, With, Without,
|
||||||
};
|
};
|
||||||
use bevy_rapier3d::{
|
use bevy_rapier3d::{
|
||||||
dynamics::MassProperties,
|
dynamics::MassProperties,
|
||||||
|
@ -135,6 +135,7 @@ pub(super) fn wheel_forces(
|
||||||
&Transform,
|
&Transform,
|
||||||
&Velocity,
|
&Velocity,
|
||||||
&mut PreviousVelocity,
|
&mut PreviousVelocity,
|
||||||
|
&mut ExternalForce,
|
||||||
Option<&CyberSteering>,
|
Option<&CyberSteering>,
|
||||||
),
|
),
|
||||||
(With<CyberWheel>, Without<CyberBikeBody>),
|
(With<CyberWheel>, Without<CyberBikeBody>),
|
||||||
|
@ -168,31 +169,42 @@ pub(super) fn wheel_forces(
|
||||||
// we're just projecting onto the ground, so nuke the Y.
|
// we're just projecting onto the ground, so nuke the Y.
|
||||||
body_forward.y = 0.0;
|
body_forward.y = 0.0;
|
||||||
let body_half_mass = body_mass.mass * 0.5;
|
let body_half_mass = body_mass.mass * 0.5;
|
||||||
let g = gvec * settings.gravity * body_half_mass;
|
let half_weight = settings.gravity * body_half_mass;
|
||||||
|
|
||||||
// inputs
|
// inputs
|
||||||
let steering_angle = yaw_to_angle(input.yaw);
|
let steering = input.yaw;
|
||||||
let throttle = input.throttle * settings.accel;
|
let throttle = input.throttle * settings.accel;
|
||||||
|
|
||||||
for (xform, vel, mut pvel, steering) in wheels_query.iter_mut() {
|
for (xform, vel, mut pvel, mut force, steering) in wheels_query.iter_mut() {
|
||||||
if let Some((_, projected)) =
|
if let Some((_, projected)) =
|
||||||
context.project_point(xform.translation, true, QueryFilter::only_fixed())
|
context.project_point(xform.translation, true, QueryFilter::only_fixed())
|
||||||
{
|
{
|
||||||
let normal = -(projected.point - xform.translation);
|
info!("projected point: {:?}", projected.point);
|
||||||
|
//dbg!("{:?}", projected);
|
||||||
|
let normal = (projected.point - xform.translation);
|
||||||
let len = normal.length();
|
let len = normal.length();
|
||||||
let normal = normal.normalize();
|
let normal = normal.normalize();
|
||||||
if len < wheel_config.radius {
|
if len < wheel_config.radius {
|
||||||
// we're in contact
|
let grav_norm = gvec.normalize().dot(normal);
|
||||||
|
// we're in contact, first gravity
|
||||||
// do gravity's share
|
let inside = if projected.is_inside { -1.0 } else { 1.0 };
|
||||||
|
let mut force = inside * 10.0 * grav_norm * half_weight * normal;
|
||||||
|
|
||||||
// do linear acceleration's share
|
// do linear acceleration's share
|
||||||
|
// f = ma
|
||||||
|
let lin_accel_norm = normal.dot(body_lin_accel.normalize());
|
||||||
|
force += body_mass.mass * lin_accel_norm * body_lin_accel;
|
||||||
|
|
||||||
// do friction's share
|
// do angular accelerations's share?
|
||||||
|
|
||||||
// do thrust's share
|
// do friction's share (depends on previous three)
|
||||||
|
|
||||||
// do steering's share
|
// do thrust's share (depends on friction):
|
||||||
|
//
|
||||||
|
// let ef = ExternalForce::at_point(force, point,
|
||||||
|
// center_of_mass);
|
||||||
|
|
||||||
|
// do steering's share (also depends on friction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue