use torus for wheel instead of ball; is not oriented correctly

This commit is contained in:
Joe Ardent 2023-02-22 14:02:24 -08:00
parent a4189342e0
commit 122bf51879
2 changed files with 24 additions and 3 deletions

View File

@ -22,6 +22,7 @@ pub struct WheelConfig {
pub stiffness: f32,
pub damping: f32,
pub radius: f32,
pub thickness: f32,
pub friction: f32,
pub restitution: f32,
pub density: f32,
@ -36,7 +37,8 @@ impl Default for WheelConfig {
limits: [-0.5, 0.1],
stiffness: 50.0,
damping: 8.0,
radius: 0.3,
radius: 0.35,
thickness: 0.10,
friction: 1.2,
restitution: 0.8,
density: 0.6,

View File

@ -1,4 +1,4 @@
use bevy::prelude::{shape::UVSphere as Tire, *};
use bevy::prelude::{shape::Torus as Tire, *};
use bevy_rapier3d::prelude::{
Ccd, CoefficientCombineRule, Collider, ColliderMassProperties, CollisionGroups, Damping,
ExternalForce, Friction, MultibodyJoint, PrismaticJointBuilder, Restitution,
@ -17,6 +17,7 @@ pub fn spawn_tires(
let wheels_collision_group = CollisionGroups::new(membership, filter);
let wheel_y = conf.y;
let wheel_rad = conf.radius;
let tire_thickness = conf.thickness;
let stiffness = conf.stiffness;
let not_sleeping = Sleeping::disabled();
let ccd = Ccd { enabled: true };
@ -26,6 +27,7 @@ pub fn spawn_tires(
let tire = Tire {
radius: wheel_rad,
ring_radius: tire_thickness,
..Default::default()
};
let material = StandardMaterial {
@ -74,7 +76,24 @@ pub fn spawn_tires(
linear_damping: 0.8,
..Default::default()
};
let wheel_collider = Collider::ball(wheel_rad);
let mesh = Mesh::from(tire);
let mut idxs = Vec::new();
let indices = mesh.indices().unwrap().iter().collect::<Vec<_>>();
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::from_bevy_mesh(&mesh, computed_shape);
let mass_props = ColliderMassProperties::Density(conf.density);
let damping = conf.damping;