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

View file

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