has joint for steering, can't seem to control it
This commit is contained in:
parent
fd4155ceab
commit
4f60743192
2 changed files with 27 additions and 10 deletions
|
@ -8,7 +8,7 @@ use bevy::prelude::{
|
||||||
use bevy_rapier3d::{
|
use bevy_rapier3d::{
|
||||||
prelude::{
|
prelude::{
|
||||||
CollisionGroups, ExternalForce, Group, MultibodyJoint, QueryFilter, RapierConfiguration,
|
CollisionGroups, ExternalForce, Group, MultibodyJoint, QueryFilter, RapierConfiguration,
|
||||||
RapierContext, ReadMassProperties, Velocity,
|
RapierContext, ReadMassProperties, RevoluteJoint, Velocity,
|
||||||
},
|
},
|
||||||
rapier::prelude::JointAxis,
|
rapier::prelude::JointAxis,
|
||||||
};
|
};
|
||||||
|
@ -87,12 +87,12 @@ pub(super) fn falling_cat(
|
||||||
pub(super) fn input_forces(
|
pub(super) fn input_forces(
|
||||||
settings: Res<MovementSettings>,
|
settings: Res<MovementSettings>,
|
||||||
input: Res<InputState>,
|
input: Res<InputState>,
|
||||||
mut braking_query: Query<&mut MultibodyJoint, With<CyberWheel>>,
|
mut braking_query: Query<&mut MultibodyJoint, (Without<CyberSteering>, With<CyberWheel>)>,
|
||||||
mut body_query: Query<
|
mut body_query: Query<
|
||||||
(&Transform, &mut ExternalForce),
|
(&Transform, &mut ExternalForce),
|
||||||
(With<CyberBikeBody>, Without<CyberSteering>),
|
(With<CyberBikeBody>, Without<CyberSteering>),
|
||||||
>,
|
>,
|
||||||
mut steering_query: Query<&mut Transform, With<CyberSteering>>,
|
mut steering_query: Query<&mut MultibodyJoint, With<CyberSteering>>,
|
||||||
) {
|
) {
|
||||||
let (xform, mut forces) = body_query.single_mut();
|
let (xform, mut forces) = body_query.single_mut();
|
||||||
|
|
||||||
|
@ -105,12 +105,16 @@ pub(super) fn input_forces(
|
||||||
// brake
|
// brake
|
||||||
for mut motor in braking_query.iter_mut() {
|
for mut motor in braking_query.iter_mut() {
|
||||||
let factor = if input.brake { settings.accel } else { 0.0 };
|
let factor = if input.brake { settings.accel } else { 0.0 };
|
||||||
motor.data.set_motor_velocity(JointAxis::X, 0.0, factor);
|
motor.data = *motor.data.set_motor_velocity(JointAxis::X, 0.0, factor);
|
||||||
|
//dbg!(&motor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// steering
|
// steering
|
||||||
let angle = input.yaw * (PI / 2.0);
|
let angle = input.yaw * (PI / 2.0);
|
||||||
//let mut steering = steering_query.single_mut();
|
let mut steering = steering_query.single_mut();
|
||||||
|
steering.data = *steering
|
||||||
|
.data
|
||||||
|
.set_motor_position(JointAxis::AngY, angle, 20.0, 1.0);
|
||||||
//steering.rotation = Quat::from_axis_angle(Vec3::Y, angle +
|
//steering.rotation = Quat::from_axis_angle(Vec3::Y, angle +
|
||||||
// 90.0f32.to_radians()); dbg!(steering.rotation);
|
// 90.0f32.to_radians()); dbg!(steering.rotation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use bevy_rapier3d::prelude::{
|
||||||
RevoluteJointBuilder, RigidBody, Sleeping, TransformInterpolation,
|
RevoluteJointBuilder, RigidBody, Sleeping, TransformInterpolation,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{CyberWheel, Meshterial, WheelConfig, BIKE_WHEEL_COLLISION_GROUP};
|
use super::{CyberSteering, CyberWheel, Meshterial, WheelConfig, BIKE_WHEEL_COLLISION_GROUP};
|
||||||
|
|
||||||
pub fn spawn_tires(
|
pub fn spawn_tires(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
|
@ -58,7 +58,7 @@ pub fn spawn_tires(
|
||||||
let wheel_x = 0.0;
|
let wheel_x = 0.0;
|
||||||
let wheel_z = -conf.front_forward;
|
let wheel_z = -conf.front_forward;
|
||||||
let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
|
let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
|
||||||
wheel_poses.push(offset);
|
wheel_poses.push((offset, Some(CyberSteering)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// rear
|
// rear
|
||||||
|
@ -66,10 +66,10 @@ pub fn spawn_tires(
|
||||||
let wheel_x = 0.0;
|
let wheel_x = 0.0;
|
||||||
let wheel_z = conf.rear_back;
|
let wheel_z = conf.rear_back;
|
||||||
let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
|
let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
|
||||||
wheel_poses.push(offset);
|
wheel_poses.push((offset, None));
|
||||||
}
|
}
|
||||||
|
|
||||||
for offset in wheel_poses {
|
for (offset, steering) in wheel_poses {
|
||||||
let wheel_damping = Damping {
|
let wheel_damping = Damping {
|
||||||
linear_damping: 0.8,
|
linear_damping: 0.8,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -88,8 +88,21 @@ pub fn spawn_tires(
|
||||||
.insert(prismatic_joint)
|
.insert(prismatic_joint)
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
|
let axel_parent = if let Some(steering) = steering {
|
||||||
|
let neck_builder = RevoluteJointBuilder::new(Vec3::Y);
|
||||||
|
let neck_joint = MultibodyJoint::new(fork_rb_entity, neck_builder);
|
||||||
|
let hub = commands
|
||||||
|
.spawn(RigidBody::Dynamic)
|
||||||
|
.insert(neck_joint)
|
||||||
|
.insert(steering)
|
||||||
|
.id();
|
||||||
|
hub
|
||||||
|
} else {
|
||||||
|
fork_rb_entity
|
||||||
|
};
|
||||||
|
|
||||||
let revolute_builder = RevoluteJointBuilder::new(Vec3::X);
|
let revolute_builder = RevoluteJointBuilder::new(Vec3::X);
|
||||||
let axel_joint = MultibodyJoint::new(fork_rb_entity, revolute_builder);
|
let axel_joint = MultibodyJoint::new(axel_parent, revolute_builder);
|
||||||
|
|
||||||
commands.spawn(pbr_bundle.clone()).insert((
|
commands.spawn(pbr_bundle.clone()).insert((
|
||||||
wheel_collider,
|
wheel_collider,
|
||||||
|
|
Loading…
Reference in a new issue