Skip to content

Commit 4ff8431

Browse files
committed
Allow customising the time until sleep for a rigid body
1 parent 1a4183c commit 4ff8431

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/dynamics/island_manager.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ impl IslandManager {
176176

177177
update_energy(&mut rb.activation, sq_linvel, sq_angvel, dt);
178178

179-
if rb.activation.time_since_can_sleep >= RigidBodyActivation::default_time_until_sleep()
180-
{
179+
if rb.activation.time_since_can_sleep >= rb.activation.time_until_sleep {
181180
// Mark them as sleeping for now. This will
182181
// be set to false during the graph traversal
183182
// if it should not be put to sleep.

src/dynamics/rigid_body_components.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@ pub struct RigidBodyActivation {
978978
pub linear_threshold: Real,
979979
/// The angular linear velocity bellow which the body can fall asleep.
980980
pub angular_threshold: Real,
981+
/// The amount of time the rigid-body must remain below the thresholds to be put to sleep.
982+
pub time_until_sleep: Real,
981983
/// Since how much time can this body sleep?
982984
pub time_since_can_sleep: Real,
983985
/// Is this body sleeping?
@@ -1012,6 +1014,7 @@ impl RigidBodyActivation {
10121014
RigidBodyActivation {
10131015
linear_threshold: Self::default_linear_threshold(),
10141016
angular_threshold: Self::default_angular_threshold(),
1017+
time_until_sleep: Self::default_time_until_sleep(),
10151018
time_since_can_sleep: 0.0,
10161019
sleeping: false,
10171020
}
@@ -1022,8 +1025,9 @@ impl RigidBodyActivation {
10221025
RigidBodyActivation {
10231026
linear_threshold: Self::default_linear_threshold(),
10241027
angular_threshold: Self::default_angular_threshold(),
1025-
sleeping: true,
1028+
time_until_sleep: Self::default_time_until_sleep(),
10261029
time_since_can_sleep: Self::default_time_until_sleep(),
1030+
sleeping: true,
10271031
}
10281032
}
10291033

@@ -1055,6 +1059,6 @@ impl RigidBodyActivation {
10551059
#[inline]
10561060
pub fn sleep(&mut self) {
10571061
self.sleeping = true;
1058-
self.time_since_can_sleep = Self::default_time_until_sleep();
1062+
self.time_since_can_sleep = self.time_until_sleep;
10591063
}
10601064
}

0 commit comments

Comments
 (0)