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
1 changed files with 54 additions and 23 deletions

View File

@ -13,7 +13,7 @@ fn spawn_bike(
mut meshes: ResMut<Assets<Mesh>>,
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 =
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| {
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));
rotation.rotate_x(FRAC_PI_2);
rotation.rotate_y(FRAC_PI_2);
let pbr_bundle = PbrBundle {
mesh: meshes.add(Capsule3d::new(0.5, 1.45)),
transform: rotation,
@ -66,16 +66,13 @@ pub struct Rearing;
#[derive(Component)]
pub struct RearHub;
fn spawn_wheels(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
xform: Transform,
body: Entity,
fn helper(
commands: &mut Commands,
trans: Vec3,
rot: Quat,
meshes: &mut ResMut<Assets<Mesh>>,
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_material = StandardMaterial {
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 front_hub = commands
let hub = commands
.spawn((
FrontHub,
SpatialBundle::from_transform(Transform::from_translation(front_pos)),
RigidBody::Dynamic,
MassPropertiesBundle::new_computed(&Collider::sphere(0.01), 1.0),
SpatialBundle::from_transform(Transform::from_translation(trans)),
RigidBody::Static,
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();
let mut tire_rot = Transform::default();
tire_rot.rotate_z(FRAC_PI_2);
let front_tire = commands
let tire = commands
.spawn((
SpatialBundle::from_transform(tire_rot),
SpatialBundle::default(),
CyberWheel,
RigidBody::Dynamic,
collider.clone(),
@ -109,7 +112,7 @@ fn spawn_wheels(
))
.with_children(|b| {
b.spawn(PbrBundle {
mesh: meshes.add(wheel_mesh.clone()),
mesh: meshes.add(wheel_mesh),
material: materials.add(wheel_material.clone()),
// transform: Transform::from_translation(front_pos)
// .with_rotation(Quat::from_rotation_z(FRAC_PI_2)),
@ -119,7 +122,35 @@ fn spawn_wheels(
.id();
// 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
commands.spawn((
@ -127,7 +158,7 @@ fn spawn_wheels(
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_hub = commands
.spawn((