Jondolf / avian

ECS-driven 2D and 3D physics engine for the Bevy game engine.
https://crates.io/crates/avian3d
Apache License 2.0
1.54k stars 120 forks source link

Negative gravity above objects with colliders #525

Closed SunkenPotato closed 1 month ago

SunkenPotato commented 1 month ago

Gravity above objects is inverted when the character moves (sometimes, I can't tell exactly when). This is my code, I'm trying to make a rigid platform to test things on:

pub fn setup_terrain(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<ColorMaterial>>, windows: Query<&Window>) {
        let window = windows.single();

        let width = window.width();

        let rect = Mesh2dHandle(meshes.add(Rectangle::new(width, 32.)));
        let color = Color::linear_rgb(1., 1., 0.);

        commands.spawn((
            MaterialMesh2dBundle {
                mesh: rect,
                material: materials.add(color),
                transform: Transform::from_xyz(0., -32., 0.),
                ..default()
            },
            Collider::rectangle(width, 32.),
            RigidBody::Static
        ));
    }

And the player...

pub fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) 
{
    commands.spawn((
        SpriteBundle {
            texture: asset_server.load(DEFAULT_PLAYER_SPRITE),
            transform: Transform::from_scale(Vec3::splat(PLAYER_SCALE)).with_translation(Vec3 { x: 0., y: 32., z: 0.}),
            ..default()
        },
        Player::default(),
        Speed::default(2.0),
        Health(20.),
        Direction::L,
        Collider::rectangle(PLAYER_SIZE.0, PLAYER_SIZE.1),
        RigidBody::Dynamic
    ));
}

Is this a bug? Or is it just my code? image The character floats up until a certain point, and then stops floating automatically unless I move it.

SunkenPotato commented 1 month ago

Never mind, my hitboxes are wrong.