You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use bevy::pbr::MeshMaterial3d;use bevy::prelude::*;use bevy::render::mesh::Mesh3d;use bevy_rapier3d::prelude::*;use game_flori::camera_0::*;#[derive(Component)]structTheSphere;fnstop_fall(mutq_sphere:Query<(&mutVelocity,&Transform),With<TheSphere>>){for(mut vel, transform)in q_sphere.iter_mut(){let pos = transform.translation;if pos.y < 0.0{
vel.linvel = Vec3::ZERO;continue;}}}fnsetup(mutcommands:Commands,mutmeshes:ResMut<Assets<Mesh>>,mutmaterials:ResMut<Assets<StandardMaterial>>,){// A camera
commands.spawn((Camera3d::default(),Transform::from_xyz(-2.5,4.5,9.0).looking_at(Vec3::ZERO,Vec3::Y),Projection::from(PerspectiveProjection{near:0.1,far:1000.0,fov:70.0_f32.to_radians(),
..default()}),CameraController::default(),));// A spherelet sphere_material = materials.add(StandardMaterial{base_color:Color::srgb(1.0,0.0,0.0),
..Default::default()});
commands.spawn((Transform::from_xyz(3.0,15.0,0.0),GlobalTransform::default(),Collider::ball(1.0),RigidBody::Dynamic,Damping{linear_damping:0.0,angular_damping:0.0,},Restitution::coefficient(0.7),Mesh3d(meshes.add(Sphere::new(1.0).mesh())),MeshMaterial3d(sphere_material),Velocity::default(),TheSphere,));// A floor or something
commands.spawn((Transform::from_xyz(0.0,0.0,0.0),GlobalTransform::default(),// Collider::cuboid(10.0, 0.2, 10.0),Mesh3d(meshes.add(Cuboid::new(10.0,0.2,10.0).mesh())),MeshMaterial3d(materials.add(StandardMaterial{base_color:Color::srgb(0.3,0.5,0.3),
..Default::default()})),));}fnmain(){App::new().add_plugins(DefaultPlugins).add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin).add_plugins(bevy::diagnostic::EntityCountDiagnosticsPlugin).add_plugins(bevy::diagnostic::SystemInformationDiagnosticsPlugin).add_plugins(RapierPhysicsPlugin::<NoUserData>::default()).add_plugins(RapierDebugRenderPlugin::default()).add_systems(Startup, setup).add_systems(Update, stop_fall).run();}
The relevant line is vel.linvel = Vec3::ZERO;, in theory the ball should stop past the 0-th height in the Y axis. Instead, it just falls very slowly? I know I could add a collider on the box, but I need this "artificial force setting" for other things. I've been reading the docs but I can't find much info about this... am I missing anything?
The text was updated successfully, but these errors were encountered:
It comes from the gravity, applied after accounting for the velocity. I'll have to research how gravity is handled in other physics engines, to see if that's expected. In the meantime you can manually add a GravityScale to your object and set it to 0 when you don't want it applied.
Thanks!! In a way I wanted this because I was experimenting with "large scale mathematical" collision meshes. I guess the way to go is just to generate collision meshes, but that gets very slow when you have complex geometries...
So I made this dummy code example using
The relevant line is
vel.linvel = Vec3::ZERO;
, in theory the ball should stop past the 0-th height in the Y axis. Instead, it just falls very slowly? I know I could add a collider on the box, but I need this "artificial force setting" for other things. I've been reading the docs but I can't find much info about this... am I missing anything?The text was updated successfully, but these errors were encountered: