Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LockedAxes #64

Merged
merged 2 commits into from
Jul 9, 2023
Merged

Add LockedAxes #64

merged 2 commits into from
Jul 9, 2023

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Jul 9, 2023

Adds a LockedAxes component for locking translational and rotational axes.

The locked axes are represented as a u8, where each axis has one bit, a total of 6 bits. There are methods like lock_translation_x, lock_rotation_y and unlock_rotation_z, and the constants TRANSLATION_LOCKED, ROTATION_LOCKED and ALL_LOCKED.

To take the locked axes into account, an effective mass/inertia is computed before applying any positional or rotational updates. For example the effective mass is just a vector where the locked axes have a mass of zero. This works similarly for other updates.

Example

use bevy::prelude::*;
use bevy_xpbd_3d::prelude::*;

fn spawn(mut commands: Commands) {
    // Spawn a capsule that only rotates around the Y axis
    commands.spawn((
        RigidBody::Dynamic,
        Collider::capsule(1.0, 0.5),
        // In 2D, use use LockedAxes::new().lock_rotation()
        LockedAxes::new().lock_rotation_x().lock_rotation_z(),
    ));
}

@Jondolf Jondolf added the C-Enhancement New feature or request label Jul 9, 2023
@Jondolf Jondolf merged commit b3a500d into main Jul 9, 2023
@Jondolf Jondolf deleted the locked-axes branch July 9, 2023 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant