still not working

This commit is contained in:
Joe Ardent 2024-07-13 12:27:36 -07:00
parent 5cfc2f7033
commit 3f965652d1
2 changed files with 27 additions and 60 deletions

View File

@ -1,7 +1,4 @@
use avian3d::prelude::{
Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction,
ReadMassProperties, Restitution, RigidBody, Sleeping, TransformInterpolation, Velocity,
};
use avian3d::prelude::*;
use bevy::{
prelude::{AssetServer, BuildChildren, Commands, Quat, Res, SpatialBundle, Transform, Vec3},
scene::SceneBundle,
@ -24,14 +21,10 @@ pub(super) fn spawn_cyberbike(
let right = xform.right() * 350.0;
xform.translation += right;
let damping = Damping {
angular_damping: 2.0,
linear_damping: 0.1,
};
let friction = Friction {
coefficient: 0.01,
..Default::default()
dynamic_coefficient: 0.1,
static_coefficient: 0.6,
combine_rule: CoefficientCombine::Average,
};
let restitution = Restitution {
@ -39,10 +32,8 @@ pub(super) fn spawn_cyberbike(
..Default::default()
};
let mass_properties = ColliderMassProperties::Density(1.5);
let (membership, filter) = BIKE_BODY_COLLISION_GROUP;
let bike_collision_group = CollisionGroups::new(membership, filter);
let bike_collision_group = CollisionLayers::new(membership, filter);
let scene = asset_server.load("cb-no-y_up.glb#Scene0");
@ -51,26 +42,23 @@ pub(super) fn spawn_cyberbike(
..Default::default()
};
let body =
Collider::capsule_endpoints(0.5, Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8));
let bike = commands
.spawn(RigidBody::Dynamic)
.insert(spatialbundle)
.insert((
Collider::capsule(Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8), 0.5),
body,
bike_collision_group,
mass_properties,
damping,
restitution,
friction,
Sleeping::disabled(),
Ccd { enabled: true },
ReadMassProperties::default(),
SleepingDisabled,
LinearDamping(0.1),
AngularDamping(2.0),
LinearVelocity::ZERO,
AngularVelocity::ZERO,
ExternalForce::ZERO,
))
.insert(TransformInterpolation {
start: None,
end: None,
})
.insert(Velocity::zero())
.insert(ExternalForce::default())
.with_children(|rider| {
rider.spawn(SceneBundle {
scene,

View File

@ -1,9 +1,5 @@
use avian3d::prelude::{
Ccd, CoefficientCombineRule, Collider, ColliderMassProperties, CollisionGroups, Damping,
ExternalForce, Friction, MultibodyJoint, PrismaticJointBuilder, Restitution,
RevoluteJointBuilder, RigidBody, Sleeping, TransformInterpolation,
};
use bevy::prelude::{shape::Torus as Tire, *};
use avian3d::prelude::*;
use bevy::prelude::{Torus as Tire, *};
use super::{CyberSteering, CyberWheel, Meshterial, WheelConfig, BIKE_WHEEL_COLLISION_GROUP};
@ -14,18 +10,19 @@ pub fn spawn_wheels(
meshterials: &mut Meshterial,
) {
let (membership, filter) = BIKE_WHEEL_COLLISION_GROUP;
let wheels_collision_group = CollisionGroups::new(membership, filter);
let wheels_collision_group = CollisionLayers::new(membership, filter);
let wheel_y = conf.y;
let stiffness = conf.stiffness;
let not_sleeping = Sleeping::disabled();
let ccd = Ccd { enabled: true };
let not_sleeping = SleepingDisabled;
let ccd = SweptCcd::NON_LINEAR.include_dynamic(false);
let limits = conf.limits;
let (meshes, materials) = meshterials;
let rake_vec: Vec3 = Vec3::new(0.0, 1.0, 0.57).normalize(); // about 30 degrees of rake
let friction = Friction {
coefficient: conf.friction,
combine_rule: CoefficientCombineRule::Average,
dynamic_coefficient: conf.friction,
static_coefficient: conf.friction,
combine_rule: CoefficientCombine::Average,
};
let mut wheel_poses = Vec::with_capacity(2);
@ -50,12 +47,7 @@ pub fn spawn_wheels(
let (mesh, collider) = gen_tires(conf);
let material = StandardMaterial {
base_color: Color::Rgba {
red: 0.01,
green: 0.01,
blue: 0.01,
alpha: 1.0,
},
base_color: Color::linear_rgba(0.01, 0.01, 0.01, 1.0),
alpha_mode: AlphaMode::Opaque,
perceptual_roughness: 0.5,
..Default::default()
@ -67,7 +59,6 @@ pub fn spawn_wheels(
..Default::default()
};
let mass_props = ColliderMassProperties::Density(conf.density);
let suspension_damping = conf.damping;
let suspension_axis = if steering.is_some() {
@ -111,7 +102,6 @@ pub fn spawn_wheels(
commands.spawn(pbr_bundle).insert((
collider,
mass_props,
wheel_damping,
ccd,
not_sleeping,
@ -122,8 +112,8 @@ pub fn spawn_wheels(
ExternalForce::default(),
Restitution::new(conf.restitution),
SpatialBundle::default(),
TransformInterpolation::default(),
RigidBody::Dynamic,
ColliderDensity(0.1),
));
}
}
@ -133,9 +123,8 @@ fn gen_tires(conf: &WheelConfig) -> (Mesh, Collider) {
let wheel_rad = conf.radius;
let tire_thickness = conf.thickness;
let tire = Tire {
radius: wheel_rad,
ring_radius: tire_thickness,
..Default::default()
minor_radius: tire_thickness,
major_radius: wheel_rad,
};
let mut mesh = Mesh::from(tire);
@ -161,17 +150,7 @@ fn gen_tires(conf: &WheelConfig) -> (Mesh, Collider) {
for idx in indices.as_slice().chunks_exact(3) {
idxs.push([idx[0] as u32, idx[1] as u32, idx[2] as u32]);
}
let wheel_collider = Collider::convex_decomposition(
&mesh
.attribute(Mesh::ATTRIBUTE_POSITION)
.unwrap()
.as_float3()
.unwrap()
.iter()
.map(|v| Vec3::from_array(*v))
.collect::<Vec<_>>(),
&idxs,
);
let wheel_collider = Collider::convex_decomposition_from_mesh(&mesh).unwrap();
(mesh, wheel_collider)
}