ECS-driven 2D and 3D physics engine for the Bevy game engine.
APACHE-2.0 License
Bot releases are hidden (Show)
A full diff of what has been fixed can be seen here: v0.1.1...v0.1.2
Published by Jondolf 2 months ago
A full diff of what has been fixed can be seen here: v0.1.0...v0.1.1
Published by Jondolf 3 months ago
Avian Physics 0.1 has been released! 🪶
Avian is an ECS-driven physics engine for the Bevy game engine. It is the next evolution of Bevy XPBD, with a completely rewritten contact solver, improved performance, a reworked structure, and numerous other improvements and additions over its predecessor.
See #346 for background on the rebrand.
Avian 0.1 has a ton of improvements, additions, and fixes over Bevy XPBD 0.4. Some highlights:
Check out the announcement blog post for a more in-depth overview of what has changed and why. A more complete changelog can also be found after the migration guide below.
Note: This guide is for migration from Bevy XPBD 0.4 to Avian 0.1. The entries for migration to Bevy XPBD 0.5 (an easier migration path) still apply and are also listed here.
The contact solver has been rewritten. In practice, this has the following effects:
However:
SolverConfig
resource.PhysicsLengthUnit
to get the best stability and behavior.The PhysicsLengthUnit
can be thought of a pixels-per-meter scaling factor for the engine's internal length-based tolerances and thresholds, such as the maximum speed at which overlap is resolved, or the speed threshold for allowing bodies to sleep. It does not scale common user-facing inputs or outputs like colliders or velocities.
To configure the PhysicsLengthUnit
, you can insert it as a resource, or simply set it while adding PhysicsPlugins
:
fn main() {
  App::new()
    .add_plugins((
      DefaultPlugins,
      // A 2D game with 20 pixels per meter
      PhysicsPlugins::default().with_length_unit(20.0),
    ))
    .run();
}
Collider
Constructor Argument Order #394
To match Bevy's Cylinder
, Capsule
, and Cone
, the order of arguments has changed for some Collider
constructors.
Collider::cylinder(radius, height)
instead of Collider::cylinder(height, radius)
.Collider::capsule(radius, height)
instead of Collider::capsule(height, radius)
.Collider::capsule_endpoints(radius, a, b)
instead of Collider::capsule_endpoints(a, b, radius)
.Collider::cone(radius, height)
instead of Collider::cone(height, radius)
.This is a very heavily breaking change, but I believe it is important that we align ourselves with Bevy here, and it's better to do it sooner rather than later.
AsyncCollider
and AsyncSceneCollider
#378
AsyncCollider
, AsyncSceneCollider
, and ComputedCollider
have been replaced by more powerful ColliderConstructor
and ColliderConstructorHierarchy
types. They work similarly, but also support primitive shapes and arbitrary hierarchies, not just colliders computed for meshes and scenes.
Additionally, some naming changes have been made to improve consistency, such as renaming TriMesh
to Trimesh
to be consistent with Collider::trimesh
.
async-collider
. If you need to use computed shapes, use the feature collider-from-mesh
. If you depend on ColliderConstructorHierarchy
waiting for a scene to load, use the feature bevy_scene
AsyncCollider
and use ColliderConstructor
directlyAsyncSceneCollider
to ColliderConstructorHierarchy
AsyncSceneCollider::default_shape
to ColliderConstructorHierarchy::default_constructor
AsyncSceneCollider::meshes_by_name
to ColliderConstructorHierarchy::config
AsyncSceneCollider::with_shape_for_name
to ColliderConstructorHierarchy::with_constructor_for_name
AsyncSceneCollider::without_shape_for_name
to ColliderConstructorHierarchy::without_constructor_for_name
AsyncSceneColliderData
to ColliderConstructorHierarchyConfig
AsyncSceneColliderData::shape
to ColliderConstructorHierarchyConfig::constructor
ComputedCollider
to ColliderConstructor
.
ComputedCollider::TriMesh
to ColliderConstructor::TrimeshFromMesh
ComputedCollider::TriMeshWithFlags
to ColliderConstructor::TrimeshFromMeshWithConfig
ComputedCollider::ConvexHull
to ColliderConstructor::ConvexHullFromMesh
ComputedCollider::ConvexDecomposition
to ColliderConstructor::ConvexDecompositionFromMeshWithConfig
VHACDParameters
to VhacdParameters
Collider::halfspace
to Collider::half_space
prelude
should work like before, but explicit import paths may be broken.PhysicsSetupPlugin
has been split into PhysicsSchedulePlugin
and PhysicsTypeRegistrationPlugin
.Colliders with the Sensor
component no longer contribute to the mass properties of rigid bodies. You can add mass for them by adding another collider that is not a sensor, or by manually adding mass properties with the MassPropertiesBundle
or its components.
Additionally, the mass properties of Sensor
colliders are no longer updated automatically, unless the Sensor
component is removed.
SphericalJoint
no longer exists in 2D. Use RevoluteJoint
instead.AngleLimit
properties alpha
and beta
are now named min
and max
.apply_positional_correction
has been renamed to apply_positional_lagrange_update
. There is also an apply_positional_impulse
method.apply_angular_correction
has been renamed to apply_angular_lagrange_update
. There is also an apply_angular_impulse
method.compute_lagrange_update
no longer takes a slice over gradients. For that, use compute_lagrange_update_with_gradients
.Joint::align_orientation
has been moved to AngularConstraint
.dynamics::solver::xpbd
module.solve_constraints
in SubstepSolverSet::SolveUserConstraints
instead of SubstepSet::SolveUserConstraints
.Several scheduling internals have been changed. For example:
PostProcessCollisions
schedule are now run in PhysicsStepSet::NarrowPhase
instead of SubstepSet::NarrowPhase
.IntegrationSet::Velocity
and IntegrationSet::Position
instead of SubstepSet::Integrate
.SubstepSet
has been removed.
PhysicsStepSet::Solver
.SolverSet
.SolverSet::Substep
.SubstepSolverSet
.Systems running in PostProcessCollisions
may need to be modified to account for it being moved outside of the substepping loop.
Some PrepareSet
system sets have also changed order.
Before:
PreInit
PropagateTransforms
InitRigidBodies
InitMassProperties
InitColliders
InitTransforms
Finalize
After:
PreInit
InitRigidBodies
InitColliders
PropagateTransforms
InitMassProperties
InitTransforms
Finalize
ColliderHierarchyPlugin
#377
Hierarchy and transform logic for colliders has been extracted from the ColliderBackendPlugin
into a new ColliderHierarchyPlugin
, which by default is included in the PhysicsPlugins
plugin group.
If you are adding plugins manually, make sure you have both if you want that functionality.
Rotation
Component #370
The Rotation
component has been updated to match the API of Bevy's new Rot2
type more closely.
The primary breaking changes are that rotate
and mul
have been deprecated in favor of Mul
implementations, and the 2D from_radians
and from_degrees
have been renamed to just radians
and degrees
.
// Before
let rotation = Rotation::from_degrees(45.0);
assert_eq!(rotation.mul(rotation).rotate(Vec2::X), Vec2::Y);
// After
let rotation = Rotation::degrees(45.0);
assert_eq!(rotation * rotation * Vec2::X, Vec2::Y);
Add
and Sub
implementations have also been removed, as adding or subtracting quaternions in 3D is not quite equivalent to performing rotations, which can be a footgun, and having the 2D version function differently would also be inconsistent.
Note: These are changes made between Bevy XPBD 0.4 and Avian 0.1.
ShapeHits
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/340
compile_error!
macro instead of panicking in PhysicsLayer
derive macro by @doonv in https://github.com/Jondolf/bevy_xpbd/pull/347
prepare/init_transforms
system by @exoexo-dev in https://github.com/Jondolf/bevy_xpbd/pull/360
RegularPolygon
colliders with a custom shape by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/367
Rotation
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/370
ColliderTransform
propagation and extract collider hierarchy logic into ColliderHierarchyPlugin
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/377
#[reflect(Serialize, Deserialize)]
and register more types by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/395
Full Changelog: https://github.com/Jondolf/bevy_xpbd/compare/xpbd-v0.4.0...v0.1.0
Published by Jondolf 4 months ago
Bevy XPBD 0.5 is the final version of Bevy XPBD, and will be deprecated in favor of Avian, which is coming very, very soon. This release is primarily a Bevy 0.14 upgrade with very few breaking changes to ease migration. Avian 0.1 will have the majority of the changes.
The main changes and improvements in Bevy XPBD 0.5 are:
Vec2
instead of a scalar value for scale.Colliders with the Sensor
component no longer contribute to the mass properties of rigid bodies. You can add mass for them by adding another collider that is not a sensor, or by manually adding mass properties with the MassPropertiesBundle
or its components.
Additionally, the mass properties of Sensor
colliders are no longer updated automatically, unless the Sensor
component is removed.
PrepareSet
System Set Order (#380)Some PrepareSet
system sets have changed order.
Before:
PreInit
PropagateTransforms
InitRigidBodies
InitMassProperties
InitColliders
InitTransforms
Finalize
After:
PreInit
InitRigidBodies
InitColliders
PropagateTransforms
InitMassProperties
InitTransforms
Finalize
ColliderHierarchyPlugin
(#377)Hierarchy and transform logic for colliders has been extracted from the ColliderBackendPlugin
into a new ColliderHierarchyPlugin
, which by default is included in the PhysicsPlugins
plugin group.
If you are adding plugins manually, make sure you have both if you want that functionality.
ShapeHits
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/340
compile_error!
macro instead of panicking in PhysicsLayer
derive macro by @doonv in https://github.com/Jondolf/bevy_xpbd/pull/347
prepare/init_transforms
system by @exoexo-dev in https://github.com/Jondolf/bevy_xpbd/pull/360
RegularPolygon
colliders with a custom shape by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/367
ColliderTransform
propagation and extract collider hierarchy logic into ColliderHierarchyPlugin
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/377
GlobalTransform
updates for entities with non-physics children by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/392
Full Changelog: https://github.com/Jondolf/bevy_xpbd/compare/v0.4.0...v0.5.0
Published by Jondolf 8 months ago
Bevy XPBD 0.4 features several new features, bug fixes, and quality of life improvements. Here are some highlights:
Collider
for collision detection. You can implement custom collision backends!Collision
events and the Collisions
resource.PhysicsGizmos
gizmo config group: Debug rendering has its own gizmo configuration instead of using the global configuration.Check out the announcement blog post for a more in-depth overview of what's changed and why. A more complete changelog can also be found after the migration guide below.
The default Collider
now requires either the parry-f32
or parry-f64
feature depending on the precision you are using for Bevy XPBD. However, if you don't need colliders or have a custom collision backend, you can leave the feature disabled.
Collision layers have been reworked, see #313.
LayerMask
, which is a bitmask for layers and a newtype for u32
.add_group
, remove_mask
, and so on have been removed. Instead, modify the properties directly.let layers1 = CollisionLayers::new(0b00010, 0b0111);
let layers2 = CollisionLayers::new(GameLayer::Player, [GameLayer::Enemy, GameLayer::Ground]);
let layers3 = CollisionLayers::new(LayerMask(0b0001), LayerMask::ALL);
Modifying layers is now done by modifying the memberships or filters directly:
layers.memberships.remove(GameLayer::Environment);
layers.filters.add([GameLayer::Environment, GameLayer::Tree]);
// Bitwise ops also work since we're accessing the bitmasks/layermasks directly.
layers.memberships |= GameLayer::Player; // You could also use a bitmask like 0b0010.
The PhysicsDebugConfig
resource and PhysicsDebugRenderer
system parameter have been removed in favor of the new PhysicsGizmos
gizmo configuration group.
Before:
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
PhysicsPlugins::default(),
PhysicsDebugPlugin::default(),
))
// Configure physics debug rendering
.insert_resource(PhysicsDebugConfig {
aabb_color: Some(Color::WHITE),
..default()
})
.run();
}
After:
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
PhysicsPlugins::default(),
PhysicsDebugPlugin::default(),
))
// Configure physics debug rendering
.insert_gizmo_group(
PhysicsGizmos {
aabb_color: Some(Color::WHITE),
..default()
},
GizmoConfig::default(),
)
.run();
}
This also allows you to configure e.g. line width for just physics gizmos by configuring their GizmoConfig
.
Collider
constructors (#326)Collider::ball
with Collider::circle
in 2D and Collider::sphere
in 3DCollider::cuboid
with Collider::rectangle
in 2DFor spatial queries, replace Vec2
/Vec3
directions with Direction2d
/Direction3d
.
// Before
let caster = RayCaster::new(Vec3::ZERO, Vec3::X);
// After
let caster = RayCaster::new(Vec3::ZERO, Direction3d::X);
This applies to RayCaster
, ShapeCaster
, SpatialQuery
methods like cast_ray
, and many other methods that use directions.
cargo test
compile by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/267
clear_forces_and_impulses
public by @ActuallyHappening in https://github.com/Jondolf/bevy_xpbd/pull/257
Rotation
change detection triggering every frame by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/272
Time<Physics>
when PhysicsPlugins
are added by @johanhelsing in https://github.com/Jondolf/bevy_xpbd/pull/276
MapEntities
for AabbIntervals
by @johanhelsing in https://github.com/Jondolf/bevy_xpbd/pull/275
MapEntities
for collider components by @johanhelsing in https://github.com/Jondolf/bevy_xpbd/pull/277
Collider::set_shape
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/278
update_aabb_intervals
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/285
DistanceJoint
distance limits by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/286
Time
inconsistency after substepping loop by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/294
Collider
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/307
RigidBody
not working by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/323
ColliderBackendPlugin
and support generic colliders by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/311
Collider
optional, allowing usage without Parry or Nalgebra by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/327
Full Changelog: https://github.com/Jondolf/bevy_xpbd/compare/v0.3.0...v0.4.0
Published by Jondolf 12 months ago
0.3 is a huge release with tons of new features, bug fixes, and quality of life improvements, especially for collision detection. Here are some highlights:
Transform
Collisions
resource can be used for accessing and modifying contacts in custom systemsTransform
for positions: Transform
can be used instead of the internal Position
and Rotation
componentsTime<Physics>
and Time<Substeps>
resourcesRead the more complete changelog after the migration guide for more details.
Here is a (non-exhaustive) migration guide for migrating from 0.2 to 0.3.
Before:
fn my_system(mut collision_event_reader: EventReader<Collision>) {
for Collision(contact) in collision_event_reader.iter() {
println!("Penetration depth: {}", contact.penetration);
}
}
After:
fn my_system(mut collision_event_reader: EventReader<Collision>) {
for Collision(contacts) in collision_event_reader.read() {
for manifold in contacts.manifolds.iter() {
for contact in manifold.contacts.iter() {
println!("Penetration depth: {}", contact.penetration);
}
}
}
}
This is more verbose, but it provides multiple contact points instead just one. In the future, this will hopefully be made more ergonomic with helper methods.
A new and more powerful Collisions
resource was also added. It can be used to achieve a similar result.
Before:
let mesh = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
commands.spawn((
PbrBundle {
mesh,
transform: Transform::from_scale(Vec3::new(10.0, 1.0, 10.0)),
..default()
},
// Collider isn't scaled by transform
Collider::cuboid(10.0, 1.0, 10.0),
RigidBody::Static,
));
After:
let mesh = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
commands.spawn((
PbrBundle {
mesh,
transform: Transform::from_scale(Vec3::new(10.0, 1.0, 10.0)),
..default()
},
// Collider size takes transform scale into account
Collider::cuboid(1.0, 1.0, 1.0),
RigidBody::Static,
));
trimesh_from_bevy_mesh
→ trimesh_from_mesh
convex_decomposition_from_bevy_mesh
→ convex_decomposition_from_mesh
DeltaTime
in PhysicsSchedule
and every SubDeltaTime
in SubstepSchedule
with Time
, elsewhere explicitly use Time<Physics>
and Time<Substep>
DeltaTime
, advance the Time<Physics>
clock using time.advance_by(...)
PhysicsTimestep
with Time::new_with(Physics::fixed_hz(...))
and so onPhysicsLoop::pause/resume
with Time::<Physics>::pause/unpause
PhysicsLoop::step
with advancing the physics clock using Time::<Physics>::advance_by
PhysicsTimescale
usage with Time::<Physics>::with/set_relative_speed
SpatialQuery
methods to SpatialQueryPipeline
by @LeshaInc in https://github.com/Jondolf/bevy_xpbd/pull/77
enabled
flag to PhysicsDebugConfig
to globally disable debug rendering at runtime by @LeshaInc in https://github.com/Jondolf/bevy_xpbd/pull/78
trimesh_with_flags
and trimesh_from_bevy_mesh_with_flags
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/79
clear
methods for ray and shape hits and clear the hits on disable by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/82
init_rigid_bodies
. Fixes #88 by @LeshaInc in https://github.com/Jondolf/bevy_xpbd/pull/89
PhysicsSchedule
and SubstepSchedule
to use single-threaded executor by @LeshaInc in https://github.com/Jondolf/bevy_xpbd/pull/92
ExternalImpulse
and ExternalAngularImpulse
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/95
Transform
for moving and positioning bodies by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/96
Position
and Rotation
for colliders by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/101
NarrowPhasePlugin
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/100
Restitution
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/117
current_position
getter for RigidBodyQueryItem
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/120
CoefficientCombine
by @grace125 in https://github.com/Jondolf/bevy_xpbd/pull/126
position_to_transform
changing child Transform
z-component by @ShaddowSpy in https://github.com/Jondolf/bevy_xpbd/pull/134
Transform
initialization for children and refactor prepare.rs
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/140
insert
calls into bundles to reduce archetype count by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/151
Trigger
alias for Sensor
and improve Sensor
docs by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/160
PreviousGlobalTransform
public and derive traits by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/166
Collisions
API and docs by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/175
Dominance
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/178
ContactReportingPlugin
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/182
collision
module by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/184
ColliderDensity
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/194
SyncConfig
fields by @johanhelsing in https://github.com/Jondolf/bevy_xpbd/pull/195
ignore_self
property for RayCaster
and ShapeCaster
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/205
Transform
instead of Position
and Rotation
in examples by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/201
debug-plugin
a default feature and improve docs by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/209
actions/checkout@v4
. by @waywardmonkeys in https://github.com/Jondolf/bevy_xpbd/pull/215
Full Changelog: https://github.com/Jondolf/bevy_xpbd/compare/v0.2.0...v0.3.0
Published by Jondolf over 1 year ago
PhysicsPlugins
accepts any schedule for running the PhysicsSchedule
PhysicsTimestep::FixedOnce
LinearDamping
and AngularDamping
GravityScale
persistence
property and apply_at_point
LockedAxes
collider-from-mesh
feature and make bevy_render
optional by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/55
LinearDamping
and AngularDamping
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/56
GravityScale
component by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/57
SpatialQueryFilter
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/61
CollisionLayers
methods with_group
, without_group
etc. to add_group
, remove_group
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/62
LockedAxes
by @Jondolf in https://github.com/Jondolf/bevy_xpbd/pull/64
Full Changelog: https://github.com/Jondolf/bevy_xpbd/compare/v0.1.0...v0.2.0
Published by Jondolf over 1 year ago
Release 0.1.0