#rough collider or whatever else you call it

14 messages · Page 1 of 1 (latest)

ivory ingot
#

a black box moves under the action of a constant force along a surface consisting of tiles, each of which is a collider, it looks like the box is clinging to the edges of the tiles, is this normal behavior?

#
use bevy::{input::common_conditions::input_just_pressed, prelude::*};
use avian3d::prelude::*;

fn main () {
    App::new()
        .insert_resource(ClearColor(Color::BLACK))
        .add_plugins((
            DefaultPlugins,
            PhysicsDebugPlugin::default(),
            PhysicsPlugins::default()
        ))
        .add_systems(Startup, startup)
        .run();
}

// ---

fn startup(
    mut cmd: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {

    cmd.spawn((
        Camera3d::default(),
        Camera::default(),
        Transform::from_xyz(8., 4., 0.).looking_at(Vec3::Z * 5., Vec3::Y),
        AmbientLight {
            brightness: 500.,
            ..default()
        }
    ));


    let mesh_dim = vec3(5., 0.1, 1.);
    let tile_mesh = meshes.add(Cuboid::from_size(mesh_dim));

    for i in 0 .. 10 {
        cmd.spawn((
            Transform::from_xyz(0. , 0., i as f32),
            Mesh3d(tile_mesh.clone()),
            MeshMaterial3d(materials.add(Color::WHITE)),
            Collider::cuboid(mesh_dim.x, mesh_dim.y, mesh_dim.z),
            RigidBody::Static
        ));
    }

    let car_dim = vec3(0.5, 0.5 , 1.);
    cmd.spawn((
        Transform::from_xyz(1., 2., 0.).looking_to(Vec3::X, Vec3::Y),
        Mesh3d(meshes.add(Cuboid::from_size(car_dim))),
        MeshMaterial3d(materials.add(Color::BLACK)),
        Collider::cuboid(car_dim.x, car_dim.y, car_dim.z),
        RigidBody::Dynamic,
        ConstantForce(Vec3::Z * 0.5),
        Friction::new(0.0).with_combine_rule(CoefficientCombine::Min),
    ));

}

neat dune
#

The issue is that while sliding sideways, gravity wants to pull it down, and inherent inaccuracies in the computation mean that while checking for collisions, it might be ever so slightly lower than the edge of the other collider. At least, thats one way this can happen.

ivory ingot
#

A compound collider sounds promising, of course, but if it's made of triangles, it won't help.
A sliding object will catch on the edges of the triangles.
I already checked

#

In any case, I understand that this behavior is expected. Thanks for the answer.
I'll keep thinking about it.

sand ether
#

If you use a trimesh, there is a flag you need to set to have it function "smoother"

#

but yeah, I don't think there is any realtime physics engine that has solved ghost collisions entirely

neat dune
ivory ingot
ivory ingot
#

As it turned out, I, at the very least, didn't know what this phenomenon was called. 🙂
After reading your answers, I understood what it's called and after searching the server, I realized that I wasn't the first to suffer from it, and I won't be the last.
I found that this should help

ColliderConstructor::TrimeshFromMeshWithConfig(TrimeshFlags::FIX_INTERNAL_EDGES)

and this

 SpeculativeMargin(0.),

Not perfect, but much better than before.
I'll close the question here, thank you all.

neat dune