dimforge / dimforge/bevy_rapier
`Collider` in a bundle with `KinematicPositionBased` component has a velocity-based Lag
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 282
- PR merge metrics
- No merged PRs in 30d
Description
I can't use Colliders in inherited Bundles because collider position is updating with lag relative to this bundle transform, meshes etc.
Bundle Alisa is a parent with `RigidBody::Dynamic` component, `ExternalForces` applied to it in `Update` schedule creates a large velocity, for example 100m/s.
Bundle Bob is a child of Alisa, with `RigidBody::KinematicPositionBased` and `KinematicCharacterController` components.
Bob has no relative movement to it's parent Alisa,
Bob has Mesh in his Bundle(Tuple), that stays where it's supposed to be "sticked" to parent correctly,
Bob has `Collider::capsule` in his Bundle, that has _**HUGE velocity-based lag**_ from his mesh, parent mesh, parent collider.
In this moment there is no interaction with those objects.
```
child_id = commands
.spawn(ChildTag::default())
.insert(RigidBody::Dynamic)
.insert(Collider::capsule(Vec2::new(0., capsule_half_height), Vec2::new(0., -capsule_half_height), capsule_radius))
.insert(MaterialMesh2dBundle {
mesh: bevy::sprite::Mesh2dHandle(meshes.add(spec.capsule_form(false))),
material: materials.add(Color::rgb(0.3, 0.3, 0.3)),
transform: Transform { translation: Vec3::new(0., 0., 0.2), ..default() },
..default()
})
.insert(AdditionalMassProperties::MassProperties(
MassProperties {
mass: 75.,
principal_inertia: rectangle_inertia(75., Vec2::new(0.5, 1.75)),
..Default::default()
}
))
.insert(Sleeping { linear_threshold: -1., angular_threshold: -1., sleeping: false })
.insert(SolverGroups::new(GROUP_CHILD, Group::ALL ^ GROUP_PARENT))
.id();
if let Ok(parent_id) = parents_query.get_single() {
commands.entity(parent_id).add_child(child_id);
}
```
```
commands.spawn((
ParentTag::default(),
RigidBody::Dynamic,
Collider::compound(vec![
(Vect::new(-spec.half.x + 1., -1.), 0., Collider::cuboid(1., spec.half.y - 3.)),
(Vect::new( spec.half.x - 1., -1.), 0., Collider::cuboid(1., spec.half.y - 3.)),
(Vect::new(0., spec.half.y - 2.), 0., Collider::cuboid(spec.half.x, 2.)),
(Vect::new(0., -spec.half.y + 1.), 0., Collider::cuboid(spec.half.x, 1.)),
]),
Velocity::default(),
MaterialMesh2dBundle {
mesh: bevy::sprite::Mesh2dHandle(meshes.add(Rectangle::new(spec.dim.x, spec.dim.y))),
material: materials.add(Color::rgb(0.5, 0.5, 0.5)),
..default()
},
AdditionalMassProperties::MassProperties(
MassProperties {
mass: spec.mass,
principal_inertia: spec.inertia,
local_center_of_mass: spec.center_mass,
}
),
ExternalForce::default(),
Sleeping { linear_threshold: -1., angular_threshold: -1., sleeping: false },
SolverGroups::new(GROUP_PARENT, Group::ALL)
))
```
```
app.add_systems(Update, apply_forces.run_if(in_state(crate::commons::AppState::Game)));
```
```
pub fn apply_forces(mut query: Query<(&Forces, &Spec, &Transform, &mut ExternalForce), With>) {
for (forces, spec, transform, mut ext) in query.iter_mut() {
...
ext.force = (transform.rotation * forces.force).truncate();
ext.torque = forces.torque * spec.torque_rate;
}
}
```
this is with velocity
this is without the velocity
Capsule Mesh and capsule Collider is in the same Bundle/Tuple
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.