torii don't do the thing

This commit is contained in:
Joe Ardent 2024-07-23 17:26:07 -07:00
parent c7fd8a57d7
commit bf2d9727f5

View file

@ -13,7 +13,7 @@ fn spawn_bike(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
let xform = Transform::from_xyz(4.0, 4.0, 0.0); let xform = Transform::from_xyz(3.0, 4.0, 0.0);
let body_collider = let body_collider =
Collider::capsule_endpoints(0.5, Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8)); Collider::capsule_endpoints(0.5, Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8));
@ -37,7 +37,7 @@ fn spawn_bike(
.with_children(|builder| { .with_children(|builder| {
let color = Color::srgb(0.7, 0.05, 0.7); let color = Color::srgb(0.7, 0.05, 0.7);
let mut rotation = Transform::default(); // Transform::from_rotation(Quat::from_rotation_y(FRAC_PI_2)); let mut rotation = Transform::default(); // Transform::from_rotation(Quat::from_rotation_y(FRAC_PI_2));
rotation.rotate_x(FRAC_PI_2); rotation.rotate_y(FRAC_PI_2);
let pbr_bundle = PbrBundle { let pbr_bundle = PbrBundle {
mesh: meshes.add(Capsule3d::new(0.5, 1.45)), mesh: meshes.add(Capsule3d::new(0.5, 1.45)),
transform: rotation, transform: rotation,
@ -66,16 +66,13 @@ pub struct Rearing;
#[derive(Component)] #[derive(Component)]
pub struct RearHub; pub struct RearHub;
fn spawn_wheels( fn helper(
mut commands: Commands, commands: &mut Commands,
mut meshes: ResMut<Assets<Mesh>>, trans: Vec3,
mut materials: ResMut<Assets<StandardMaterial>>, rot: Quat,
xform: Transform, meshes: &mut ResMut<Assets<Mesh>>,
body: Entity, materials: &mut ResMut<Assets<StandardMaterial>>,
) { ) {
let rake_vec = Vec3::new(0.0, -1.0, 0.57).normalize(); // about 30 degrees
let front_pos = xform.translation + *xform.forward() + rake_vec;
let wheel_mesh: Mesh = Torus::new(0.30, 0.40).into(); let wheel_mesh: Mesh = Torus::new(0.30, 0.40).into();
let wheel_material = StandardMaterial { let wheel_material = StandardMaterial {
base_color: Color::srgb(0.01, 0.01, 0.01), base_color: Color::srgb(0.01, 0.01, 0.01),
@ -85,21 +82,27 @@ fn spawn_wheels(
}; };
let collider = Collider::convex_decomposition_from_mesh(&wheel_mesh).unwrap(); let collider = Collider::convex_decomposition_from_mesh(&wheel_mesh).unwrap();
let front_hub = commands let hub = commands
.spawn(( .spawn((
FrontHub, FrontHub,
SpatialBundle::from_transform(Transform::from_translation(front_pos)), SpatialBundle::from_transform(Transform::from_translation(trans)),
RigidBody::Dynamic, RigidBody::Static,
MassPropertiesBundle::new_computed(&Collider::sphere(0.01), 1.0), Mesh::from(Sphere::new(0.1)),
)) ))
.with_children(|parent| {
let mesh: Mesh = Sphere::new(0.1).into();
parent.spawn(PbrBundle {
mesh: meshes.add(mesh),
material: materials.add(wheel_material.clone()),
transform: Transform::from_rotation(rot),
..Default::default()
});
})
.id(); .id();
let mut tire_rot = Transform::default(); let tire = commands
tire_rot.rotate_z(FRAC_PI_2);
let front_tire = commands
.spawn(( .spawn((
SpatialBundle::from_transform(tire_rot), SpatialBundle::default(),
CyberWheel, CyberWheel,
RigidBody::Dynamic, RigidBody::Dynamic,
collider.clone(), collider.clone(),
@ -109,7 +112,7 @@ fn spawn_wheels(
)) ))
.with_children(|b| { .with_children(|b| {
b.spawn(PbrBundle { b.spawn(PbrBundle {
mesh: meshes.add(wheel_mesh.clone()), mesh: meshes.add(wheel_mesh),
material: materials.add(wheel_material.clone()), material: materials.add(wheel_material.clone()),
// transform: Transform::from_translation(front_pos) // transform: Transform::from_translation(front_pos)
// .with_rotation(Quat::from_rotation_z(FRAC_PI_2)), // .with_rotation(Quat::from_rotation_z(FRAC_PI_2)),
@ -119,7 +122,35 @@ fn spawn_wheels(
.id(); .id();
// connect hubs and tires to make wheels // connect hubs and tires to make wheels
commands.spawn(RevoluteJoint::new(front_hub, front_tire).with_aligned_axis(Vec3::X)); commands.spawn(RevoluteJoint::new(hub, tire).with_aligned_axis(Vec3::X));
}
fn spawn_wheels(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
xform: Transform,
body: Entity,
) {
let rot_x = Quat::from_rotation_x(FRAC_PI_2);
let rot_y = Quat::from_rotation_y(FRAC_PI_2);
let rot_z = Quat::from_rotation_z(FRAC_PI_2);
let trans0 = Vec3::new(0.0, 0.5, 0.0);
let trans1 = Vec3::new(1.0, 0.5, 0.0);
let trans2 = Vec3::new(2.0, 0.5, 0.0);
helper(&mut commands, trans0, rot_x, &mut meshes, &mut materials);
helper(&mut commands, trans1, rot_y, &mut meshes, &mut materials);
helper(&mut commands, trans2, rot_z, &mut meshes, &mut materials);
helper(
&mut commands,
Vec3::new(-1.0, 0.5, 0.0),
Quat::default(),
&mut meshes,
&mut materials,
);
/*
// suspension joints connect the hubs and the body // suspension joints connect the hubs and the body
commands.spawn(( commands.spawn((
@ -127,7 +158,7 @@ fn spawn_wheels(
FixedJoint::new(front_hub, body).with_local_anchor_2(*xform.forward() + rake_vec), FixedJoint::new(front_hub, body).with_local_anchor_2(*xform.forward() + rake_vec),
)); ));
/*
let rear_pos = *xform.back() + xform.translation + rake_vec.y; let rear_pos = *xform.back() + xform.translation + rake_vec.y;
let rear_hub = commands let rear_hub = commands
.spawn(( .spawn((