welp this works better

This commit is contained in:
Jay Christy
2023-11-07 01:48:05 -05:00
parent 242759eca2
commit 7a29d1bd36

View File

@@ -302,7 +302,7 @@ fn spawn_physics_hands(mut commands: Commands) {
), ),
RigidBody::KinematicVelocityBased, RigidBody::KinematicVelocityBased,
Velocity::default(), Velocity::default(),
// CollisionGroups::new(self_group, interaction_group), CollisionGroups::new(Group::from_bits(0b1110).unwrap(), Group::from_bits(0b0001).unwrap()),
// SolverGroups::new(self_group, interaction_group), // SolverGroups::new(self_group, interaction_group),
bone.clone(), bone.clone(),
BoneInitState::False, BoneInitState::False,
@@ -354,6 +354,7 @@ fn update_physics_hands(
//i hate this but we need to skip init if the length is zero //i hate this but we need to skip init if the length is zero
return; return;
} }
match *bone.3 { match *bone.3 {
BoneInitState::True => { BoneInitState::True => {
@@ -373,18 +374,14 @@ fn update_physics_hands(
/ time.delta_seconds(); / time.delta_seconds();
bone.5.linvel = diff; bone.5.linvel = diff;
//calculate angular velocity? //calculate angular velocity?
let why = direction.xy(); let desired_forward = start_components.unwrap().0.clone().looking_at(end_components.unwrap().0.translation, Vec3::Y).rotation;
let desired_forward = Quat::from_rotation_arc(bone.0.forward(), direction.normalize()); let some: Vec3 = help_me(bone.0.rotation,desired_forward);
let ang: Vec3 = why_god(
bone.0.rotation,
desired_forward,
time.delta_seconds(),
);
if *bone.2 == PhysicsHandBone::IndexIntermediate && *bone.4 == Hand::Right { if *bone.2 == PhysicsHandBone::IndexIntermediate && *bone.4 == Hand::Right {
info!("{}", ang); info!("{}", some);
// info!("{}", forward); // info!("{}", forward);
} }
bone.5.angvel = ang * PI / 180.0; bone.5.angvel = 5.0 * some / time.delta_seconds();
} }
} }
} }
@@ -409,15 +406,18 @@ fn update_physics_hands(
} }
} }
fn why_god(q1: Quat, q2: Quat, dt: f32) -> Vec3 { fn help_me(rotation: Quat, desired_forward: Quat) -> Vec3 {
let huh = Vec3 { let conj = rotation.conjugate();
x: (q1.w * q2.x) - (q1.x * q2.x) - (q1.y * q2.z) + (q1.z * q2.y), let diff = desired_forward.mul_quat(conj);
y: (q1.w * q2.y) - (q1.x * q2.z) - (q1.y * q2.w) + (q1.z * q2.x), let mut test = diff.to_axis_angle();
z: (q1.w * q2.z) - (q1.x * q2.y) - (q1.y * q2.x) + (q1.z * q2.w), if test.0.x.is_infinite() {
}; return Vec3::ZERO;
let why = 2.0 / dt; }
let help = why * huh; // if test.1 > 180.0 {
return help; // test.1 = test.1 - 360.0;
// }
let ang = (0.99 * (PI / 180.0) * test.1) * test.0;
return ang;
} }
fn get_start_and_end_entities( fn get_start_and_end_entities(