#rough collider or whatever else you call it
14 messages · Page 1 of 1 (latest)
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),
));
}
Somewhat normal, yes. Theres a few ways to fix it, either using a different shape like round_rectangle or using a compound collider over all the colliders. Theres probably tons of other ways of working around it, but those are good starting points
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.
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.
If you use a trimesh, there is a flag you need to set to have it function "smoother"
Flags used for the preprocessing of a triangle mesh collider.
but yeah, I don't think there is any realtime physics engine that has solved ghost collisions entirely
the docs for compound say:
Especially for dynamic rigid bodies, compound shape colliders should be preferred over triangle meshes and polylines, because convex shapes typically provide more reliable results.
But yea, if i were you i'd try round_rectangle first
Thanks, I'll look into it and let you know if I achieve anything interesting.
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.
I mean, i know the phenomenon, i didn't know it had a name. care to share?