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

RapierPhysicsPlugin does not accept rotations over 180 degrees #438

Closed
LuukHenk opened this issue Oct 26, 2023 · 1 comment
Closed

RapierPhysicsPlugin does not accept rotations over 180 degrees #438

LuukHenk opened this issue Oct 26, 2023 · 1 comment
Labels
A-Integration very bevy specific C-Bug Something isn't working D-Medium P-Medium S-not-started Work has not started wontfix This will not be worked on

Comments

@LuukHenk
Copy link

LuukHenk commented Oct 26, 2023

In the example below, I tried to set the player rotation to 270 degrees. After I set the rotation, the RapierPhysicsPlugin sets the rotation to 90 degrees (so, flipped). Disabling the RapierPhysicsPlugin resolves the issue.
It seems that the RapierPhysicsPlugin only does this if I set the rotation over 180 degrees; is this expected, or is this a bug?

The issue might be related to #246

Cargo file:

[package]
name = "bevy_rotation_test"
version = "0.1.0"
edition = "2021"


[dependencies]
bevy = { version = "0.11", features = ["dynamic_linking"] }
bevy_rapier2d = {  version = "0.22.0", features = ["debug-render-2d"] }

### {{{ BEVY CONFIGURATION

[workspace]
resolver = "2" # Important! wgpu/Bevy needs this!

# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1

# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3

Main file:

use std::f32::consts::PI;
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;

fn main() {
    App::new()
        .add_plugins(
            (
                DefaultPlugins,
                RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(16.0), // Does something with the rotation
            )
        )
        .add_systems(Startup, setup)
        .add_systems(Update, rotate)
        .run();
}


#[derive(Component)]
pub struct PlayerMarker;

#[derive(Bundle)]
struct PlayerBundle {
    transform: Transform,
    global_transform: GlobalTransform,
    rigid_body: RigidBody,
    player_marker: PlayerMarker,
}

impl PlayerBundle {
    fn new() -> PlayerBundle {
        PlayerBundle{
            transform: Transform { ..default() },
            global_transform: GlobalTransform::default(),
            rigid_body: RigidBody::Dynamic,
            player_marker: PlayerMarker,
        }
    }
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn(PlayerBundle::new());
}

pub fn rotate(mut query: Query<&mut Transform, With<PlayerMarker>>) {
    let mut transform = query.single_mut();
    let mut degrees = transform.rotation.to_axis_angle().1 * 180.0 / PI;

    println!("Input: {:#?}", degrees);

    degrees = 270.0_f32;

    println!("output: {:#?}", degrees);

    transform.rotation = Quat::from_rotation_z(degrees.to_radians());
}
@Vrixyz Vrixyz added C-Bug Something isn't working D-Medium P-Medium S-not-started Work has not started A-Integration very bevy specific labels May 23, 2024
@Vrixyz
Copy link
Contributor

Vrixyz commented May 23, 2024

as a curiosity, how does it handle -90f32 as degrees ?

Edit:
Can you print the axis returned by to_axis_angle() ? I suspect it might be -Z, effectively setting the correct rotation. (maybe print the plain rotation or its euler degrees might help understand)

Details

dbg!(transform.rotation.to_axis_angle().0);

From a quick local test it seems to be the case, I'm closing, please comment again if need be.

@Vrixyz Vrixyz added the wontfix This will not be worked on label May 23, 2024
@Vrixyz Vrixyz closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Integration very bevy specific C-Bug Something isn't working D-Medium P-Medium S-not-started Work has not started wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants