Comments (6)
Thanks for the help and explanation ! Setting the inertia makes a lot of sense and works perfect for my case 🙂
Also haha thank you for the Vector correction. I consider myself still new to rust so I'm just happy it compiled :P but i'll make that change as well
from bevy_xpbd.
Do the planets have colliders? If they do, then the mass properties of the colliders are computed and added on top of the body's existing mass properties, like in rapier. This is documented here.
You can set the mass properties of the colliders to zero by adding ColliderMassProperties::ZERO
. With that I am not seeing any mass changing in my examples.
from bevy_xpbd.
That worked great for me ! Thank you. I'm enjoying the library :)
from bevy_xpbd.
tldr: Nvm, I'm got it :P
I feel like I'm silly for doing this but if I try to do the same thing of setting ColliderMassProperties::ZERO
with a RigidBody::Dynamic
it doesn't work and my little ball disappears off the screen before I've even added any forces to the ball.
let shape = shape::UVSphere {
radius: 1.0,
..default()
};
commands.spawn((
PbrBundle {
mesh: meshes.add(shape.into()),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
},
Collider::ball(1.0),
ColliderMassProperties::ZERO,
// RigidBody::Kinematic, // <- Works
// RigidBody::Dynamic, // <- hops off the screen before I've started my physics stuff
Position(Vector::new(14.0, 0.0, 0.0)),
ExternalForce::default(),
Mass(1.0),
Friction::new(6.0),
Junk {},
));
Again, I'm crazy dumb when it comes to physics anything so feel free to let me know if I'm just doing stuff wrong.
Edit
So I guess it just needs a non-zero density in order to not freak out:
ColliderMassProperties {
density: 1.0,
..default()
},
Mass(1.0),
RigidBody::Dynamic,
Which makes some sense. Anyways, I guess the problem now is that the mass is changing from the 1.0
I set it to to something like 6.4
😭
Edit 2
I guess setting the density to something super low actually fixes it and I get my mass of ~1.0 lol.
ColliderMassProperties {
density: 0.00001, // honestly, just non-zero prob
..default()
},
from bevy_xpbd.
I'm pretty sure the problem isn't actually the density of the collider, it's that you only add Mass
and not Inertia
as well.
Angular inertia controls how much effort it requires to rotate a body, and when there's zero inertia, there is probably some kind of division by zero happening, which breaks the simulation and causes the bodies to accelerate into infinity (making them disappear).
So I would add something like this:
(
ColliderMassProperties::ZERO,
Mass(1.0),
Inertia(1.0), // In 2D
Inertia(Mat3::IDENTITY) // In 3D
// ...other components
)
You can of course set the inertia to whatever you want, as long as it's greater than 0.
Thanks for the issue though, I definitely need to make the docs more explicit about this. I might also just add a warning when the engine detects a dynamic body with zero mass/inertia.
from bevy_xpbd.
Also FYI, it looks like you might be using the crate's math types like Vector
. This is fine, but you can also just use the normal types like Vec2
or Vec3
. The special math types are there because the crate needs to use different types depending on feature flags like 2d
/3d
and f32
/f64
, but in actual usage you already know the types because you have specified the features.
from bevy_xpbd.
Related Issues (20)
- Rotational motion ignores center of mass HOT 3
- TriMeshFlags in AsyncColliders
- Entity are overlapping at spawn, which can result in explosive behavior. HOT 2
- ColliderDensity of 0 causes cast_ray to panic
- Support for joints with with local frames (anchor position + rotation) HOT 2
- [feature] Support for child entities enacting force on parent `RigidBody` HOT 2
- Unstable joint when attached body has multiple colliders
- Debug render axes "dot" is hard-coded to 0.5 radius in 2D
- Children entity collision handling is *weird*.
- Support for use within Bevy's FixedUpdate schedule? HOT 2
- Velocity decaying to zero causes sensors to stop colliding HOT 1
- Fluid Simulation HOT 3
- Spawn non-colliding entities HOT 5
- Collision between the character and the square in the kinematic_character_2d is wonky
- Disabling Collision of Bodies Connected with a Joint
- Make Sensor Component storage type a SparseSet
- allow `AsyncSceneCollider` to take non-computed `Collider`s
- Negative scale on transforms causes collider to stop detecting collisions.
- Raycast Does Not Follow Entity Transform Without Rigidbody
- Scaling of parent entity not effecting child collider HOT 3
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.