Comments (1)
I have made a nice reproduction of the weirdness
In my example, the character is the parent of both the pressure plate and the hand. As the character moves, its position and transform are both updated, but on the children only the transform is updated. This results in the children visually following the parent while the physics position not following the parent.
If the child has a velocity, the physics logic takes priority and overwrites the transform, resulting in the child moving with a velocity independent of the parent's velocity.
In the example, I have added ghosts to show the difference between the transform and the position
child_sensor_81wsXsbMJi.mp4
This is all related to the decision to use components instead of Transform to handle the physics (#16 and #96)
/// When synchronizing changes in [`Position`] or [`Rotation`] to `Transform`,
/// the engine treats nested [rigid bodies](RigidBody) as a flat structure. This means that
/// the bodies move independently of the parents, and moving the parent will not affect the child.
///
/// If you would like a child entity to be rigidly attached to its parent, you could use a [`FixedJoint`]
/// or write your own system to handle hierarchies differently.
Here's a naΓ―ve attempt at inheriting the parent velocity. I changed the pressure plate from static to dynamic so that it also receives a velocity component that we can update.
fn inherit_velocity(
mut kids: Query<(&mut LinearVelocity, &mut AngularVelocity, &Parent), Without<Character>>,
parents: Query<(&LinearVelocity, &AngularVelocity), With<Character>>,
) {
for (mut kid_linear_velocity, mut kid_angular_velocity, parent) in &mut kids.iter_mut() {
if let Ok((parent_linear_velocity, parent_angular_velocity)) = parents.get(parent.get()) {
kid_linear_velocity.x = parent_linear_velocity.x;
kid_linear_velocity.y = parent_linear_velocity.y;
kid_angular_velocity.0 = parent_angular_velocity.0;
}
}
}
child_sensor_d2hakh2r1j.mp4
This breaks the hand movement logic because the acceleration from its inputs gets clobbered when inheriting the parent velocity. Additionally, this would cause the children to rotate in place rather than pivoting around the parent.
Overall, the decision to have separate components instead of using Transform is because the physics system is inherently flat rather than hierarchical. The ECS itself is also flat, with Parent
and Children
being conveniences. Using a joint, as recommended by the code comment, is probably the best way to solve this issue.
If you're going to manually adjust transforms to have entities follow another, watch out for: Jitter when making the camera follow a physics object
from bevy_xpbd.
Related Issues (20)
- Enabling `default-collider` without parry renders 34 compilation errors
- [Bug]: (0.4.0) Can't compile with specific crate features enabled
- [0.4.1] Colliders are initialized with wrong transform HOT 1
- Panic when running `ray_caster` example on macOS HOT 1
- inverted sign wastes hours of girls life HOT 3
- xpbd collider gen π HOT 3
- issues with 2D heightfield collider HOT 1
- Rebrand Bevy XPBD and Switch Solvers HOT 2
- CollisionEnded event not sent if collider is removed in the frame following the collision start
- RayHitData not providing enough information when hitting compound colliders HOT 1
- Panic in `debug_render_axes` HOT 2
- Cylinder collider getting stuck on ledges when dropping off of them
- Awful performance with many non-physics entities HOT 3
- Rigidbodies never sleep HOT 1
- Documentation improvements for basic setup and scheduling
- 2D physics in XZ plane
- Entity events support
- If a rigid body has any parent, it starts to infinitely shift/rotate by the amount of the parent's transformation.
- How to prevent collision Between Entities spawning in the same frame
- Why does my Transform::translation immediately get NaN values? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bevy_xpbd.