fix de-penetrator
This commit is contained in:
parent
1d9ba17911
commit
a5b9e549db
4 changed files with 108 additions and 97 deletions
|
@ -122,7 +122,7 @@ pub(super) fn surface_fix(
|
|||
cgroups.memberships = Group::NONE;
|
||||
cgroups.filters = Group::NONE;
|
||||
commands.entity(entity).insert(Tunneling {
|
||||
frames: 5,
|
||||
frames: 6,
|
||||
dir: -hit.1.normal,
|
||||
});
|
||||
}
|
||||
|
@ -135,22 +135,24 @@ pub(super) fn tunnel_out(
|
|||
(
|
||||
Entity,
|
||||
&mut Tunneling,
|
||||
&mut CollisionGroups,
|
||||
&mut ExternalForce,
|
||||
&mut CollisionGroups,
|
||||
),
|
||||
With<CyberWheel>,
|
||||
>,
|
||||
mprops: Query<&ReadMassProperties, With<CyberBikeBody>>,
|
||||
settings: Res<MovementSettings>,
|
||||
) {
|
||||
for (entity, mut tunneling, mut cgroups, mut force) in wheel_query.iter_mut() {
|
||||
let mprops = mprops.single();
|
||||
for (entity, mut tunneling, mut force, mut cgroups) in wheel_query.iter_mut() {
|
||||
if tunneling.frames == 0 {
|
||||
commands.entity(entity).remove::<Tunneling>();
|
||||
cgroups.memberships = BIKE_WHEEL_COLLISION_GROUP.0;
|
||||
cgroups.filters = BIKE_WHEEL_COLLISION_GROUP.1;
|
||||
force.force = Vec3::ZERO;
|
||||
(cgroups.memberships, cgroups.filters) = BIKE_WHEEL_COLLISION_GROUP;
|
||||
continue;
|
||||
}
|
||||
tunneling.frames -= 1;
|
||||
force.force += tunneling.dir * settings.gravity * 1.1;
|
||||
force.force = tunneling.dir * settings.gravity * 1.5 * mprops.0.mass;
|
||||
#[cfg(feature = "inspector")]
|
||||
dbg!(&tunneling);
|
||||
}
|
||||
|
|
86
src/bike/body.rs
Normal file
86
src/bike/body.rs
Normal file
|
@ -0,0 +1,86 @@
|
|||
use bevy::{
|
||||
prelude::{AssetServer, BuildChildren, Commands, Quat, Res, SpatialBundle, Transform, Vec3},
|
||||
scene::SceneBundle,
|
||||
};
|
||||
use bevy_rapier3d::prelude::{
|
||||
Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction,
|
||||
ReadMassProperties, Restitution, RigidBody, Sleeping, TransformInterpolation, Velocity,
|
||||
};
|
||||
|
||||
use super::{spawn_tires, CyberBikeBody, Meshterial, WheelConfig, BIKE_BODY_COLLISION_GROUP};
|
||||
use crate::{action::CatControllerState, planet::PLANET_RADIUS};
|
||||
|
||||
pub(super) fn spawn_cyberbike(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
wheel_conf: Res<WheelConfig>,
|
||||
mut meshterials: Meshterial,
|
||||
) {
|
||||
let altitude = PLANET_RADIUS - 220.0;
|
||||
|
||||
let mut xform = Transform::from_translation(Vec3::X * altitude)
|
||||
.with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians()));
|
||||
//.with_rotation(Quat::from_axis_angle(Vec3::X, 140.0f32.to_radians()));
|
||||
|
||||
let right = xform.right() * 350.0;
|
||||
xform.translation += right;
|
||||
|
||||
let damping = Damping {
|
||||
angular_damping: 2.0,
|
||||
linear_damping: 0.1,
|
||||
};
|
||||
|
||||
let friction = Friction {
|
||||
coefficient: 0.3,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let restitution = Restitution {
|
||||
coefficient: 0.0,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mass_properties = ColliderMassProperties::Density(0.9);
|
||||
|
||||
let (membership, filter) = BIKE_BODY_COLLISION_GROUP;
|
||||
let bike_collision_group = CollisionGroups::new(membership, filter);
|
||||
|
||||
let scene = asset_server.load("cb-no-y_up.glb#Scene0");
|
||||
|
||||
let spatialbundle = SpatialBundle {
|
||||
transform: xform,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let bike = commands
|
||||
.spawn(RigidBody::Dynamic)
|
||||
.insert(spatialbundle)
|
||||
.insert((
|
||||
Collider::capsule(Vec3::new(0.0, 0.0, -1.0), Vec3::new(0.0, 0.0, 1.0), 0.50),
|
||||
bike_collision_group,
|
||||
mass_properties,
|
||||
damping,
|
||||
restitution,
|
||||
friction,
|
||||
Sleeping::disabled(),
|
||||
Ccd { enabled: true },
|
||||
ReadMassProperties::default(),
|
||||
))
|
||||
.insert(TransformInterpolation {
|
||||
start: None,
|
||||
end: None,
|
||||
})
|
||||
.insert(Velocity::zero())
|
||||
.insert(ExternalForce::default())
|
||||
.with_children(|rider| {
|
||||
rider.spawn(SceneBundle {
|
||||
scene,
|
||||
..Default::default()
|
||||
});
|
||||
})
|
||||
.insert(CyberBikeBody)
|
||||
.insert(CatControllerState::default())
|
||||
.id();
|
||||
|
||||
spawn_tires(&mut commands, &xform, bike, &wheel_conf, &mut meshterials);
|
||||
}
|
|
@ -1,15 +1,21 @@
|
|||
mod body;
|
||||
mod components;
|
||||
mod systems;
|
||||
mod wheels;
|
||||
|
||||
use bevy::prelude::{App, Plugin, StartupStage};
|
||||
use bevy::prelude::{App, Assets, Mesh, Plugin, ResMut, StandardMaterial, StartupStage};
|
||||
use bevy_rapier3d::prelude::Group;
|
||||
|
||||
pub use self::components::*;
|
||||
use self::systems::spawn_cyberbike;
|
||||
pub(crate) use self::components::*;
|
||||
use self::{body::spawn_cyberbike, wheels::spawn_tires};
|
||||
|
||||
pub const BIKE_BODY_COLLISION_GROUP: (Group, Group) = (Group::GROUP_1, Group::GROUP_1);
|
||||
pub const BIKE_WHEEL_COLLISION_GROUP: (Group, Group) = (Group::GROUP_10, Group::GROUP_10);
|
||||
|
||||
type Meshterial<'a> = (
|
||||
ResMut<'a, Assets<Mesh>>,
|
||||
ResMut<'a, Assets<StandardMaterial>>,
|
||||
);
|
||||
|
||||
pub struct CyberBikePlugin;
|
||||
impl Plugin for CyberBikePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
|
|
|
@ -1,96 +1,13 @@
|
|||
use bevy::prelude::{shape::UVSphere as Tire, *};
|
||||
use bevy_rapier3d::prelude::{
|
||||
Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction,
|
||||
MultibodyJoint, PrismaticJointBuilder, ReadMassProperties, Restitution, RigidBody, Sleeping,
|
||||
TransformInterpolation, Velocity,
|
||||
MultibodyJoint, PrismaticJointBuilder, Restitution, RigidBody, Sleeping,
|
||||
TransformInterpolation,
|
||||
};
|
||||
|
||||
use super::{
|
||||
CyberBikeBody, CyberWheel, WheelConfig, BIKE_BODY_COLLISION_GROUP, BIKE_WHEEL_COLLISION_GROUP,
|
||||
};
|
||||
use crate::{action::CatControllerState, planet::PLANET_RADIUS};
|
||||
use super::{CyberWheel, Meshterial, WheelConfig, BIKE_WHEEL_COLLISION_GROUP};
|
||||
|
||||
type Meshterial<'a> = (
|
||||
ResMut<'a, Assets<Mesh>>,
|
||||
ResMut<'a, Assets<StandardMaterial>>,
|
||||
);
|
||||
|
||||
pub(super) fn spawn_cyberbike(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
wheel_conf: Res<WheelConfig>,
|
||||
mut meshterials: Meshterial,
|
||||
) {
|
||||
let altitude = PLANET_RADIUS - 220.0;
|
||||
|
||||
let mut xform = Transform::from_translation(Vec3::X * altitude)
|
||||
.with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians()));
|
||||
//.with_rotation(Quat::from_axis_angle(Vec3::X, 140.0f32.to_radians()));
|
||||
|
||||
let right = xform.right() * 350.0;
|
||||
xform.translation += right;
|
||||
|
||||
let damping = Damping {
|
||||
angular_damping: 2.0,
|
||||
linear_damping: 0.1,
|
||||
};
|
||||
|
||||
let friction = Friction {
|
||||
coefficient: 0.0,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let restitution = Restitution {
|
||||
coefficient: 0.0,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mass_properties = ColliderMassProperties::Density(0.9);
|
||||
|
||||
let (membership, filter) = BIKE_BODY_COLLISION_GROUP;
|
||||
let bike_collision_group = CollisionGroups::new(membership, filter);
|
||||
|
||||
let scene = asset_server.load("cb-no-y_up.glb#Scene0");
|
||||
|
||||
let spatialbundle = SpatialBundle {
|
||||
transform: xform,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let bike = commands
|
||||
.spawn(RigidBody::Dynamic)
|
||||
.insert(spatialbundle)
|
||||
.insert((
|
||||
Collider::capsule(Vec3::new(0.0, 0.0, -1.0), Vec3::new(0.0, 0.0, 1.0), 0.50),
|
||||
bike_collision_group,
|
||||
mass_properties,
|
||||
damping,
|
||||
restitution,
|
||||
friction,
|
||||
Sleeping::disabled(),
|
||||
Ccd { enabled: true },
|
||||
ReadMassProperties::default(),
|
||||
))
|
||||
.insert(TransformInterpolation {
|
||||
start: None,
|
||||
end: None,
|
||||
})
|
||||
.insert(Velocity::zero())
|
||||
.insert(ExternalForce::default())
|
||||
.with_children(|rider| {
|
||||
rider.spawn(SceneBundle {
|
||||
scene,
|
||||
..Default::default()
|
||||
});
|
||||
})
|
||||
.insert(CyberBikeBody)
|
||||
.insert(CatControllerState::default())
|
||||
.id();
|
||||
|
||||
spawn_tires(&mut commands, &xform, bike, &wheel_conf, &mut meshterials);
|
||||
}
|
||||
|
||||
fn spawn_tires(
|
||||
pub fn spawn_tires(
|
||||
commands: &mut Commands,
|
||||
xform: &Transform,
|
||||
bike: Entity,
|
Loading…
Reference in a new issue