Setting a tighter sleeping thresh hold

Hey everyone ,

I have a stone object the player is pushing. While the stone is moving it makes a rumbling sound. I’m trying to get the sound to stop when the stone stops moving. I’m using the isActive boolean of the rigidbody to determine if it’s still in motion. The problem is after it stops it takes a second or so for the object to go to sleep.

I tried adjusting the sleeping thresh hold but it still does the same thing. I also tried getting velocity but the velocity continues to move up and down a lot even when the object is at rest , at least until it goes to sleep.

Anyone have any suggestions ?

If velocity continues to move after it “stops”, wouldn’t the stone be visibly moving or bouncing around?

If velocity just takes awhile to “settle” because of physics weirdness, I would think you could use a velocity threshold check so the sound only plays when velocity is greater than X and just ignores the velocity otherwise. (I assume you’ve inspected the velocity values you get before it turns inactive?)

Not a bullet expert but I believe the isActive behavior is expected.

I’m not sure what is going on with the velocity. The z value bounces between 1 and 5 even when the object is at rest. The object is’t moving but the velocity is going wild. It only goes to zero when the object goes to sleep.

I think you would visually notice if the object was bouncing up and down by 5 meters… I’m going to guess you are looking at the wrong thing.

isActive() isn’t meant to trigger sounds. Only velocity is good for that… and you can check your own velocity and stop making the sound if it’s less than some threshold. You could even calculate your own velocity from currentPos.substract(lastPosition) if for some reason you don’t trust bullets.

I’m using the rigidbody.getLinearVelocity.tostring. My only guess is because my friction is so high when the player is at rest that the object can’t move and bullet is looking for some where to displace the momentum.

Calculating frame by frame sounds like a good idea.

You’re not curious about the cause of the z bouncing (and why you’re not seeing it visually)? That would concern me enough to keep investigating.

I did a small test case scenario and everything worked fine. It seems the mass isn’t effecting the way my rigid body moves. I tried upping the mass and gravity to ridiculous amounts and my player capsule pushes the object around like it’s a feather.

My next goal is to find out what changed between the two where the mass isn’t being applied.

I got everything straightened out with the mass and figured out what is happening with the sleeping thresh hold. The thresh hold , if set to high levels , will only stop the motion if my player capsule isn’t touching the object.

For example if I push the brick and stop in place the linear physics are still attempting to be applied because my character is touching the object regardless of if any force is applied. If I push the object then take a step back then stop the linear motion is deactivated instantly.

Looks like bullet is still apply motion if the objects are touching regardless of if any force is coming from my player.

Yes. That’s because this state is used for something completely different than triggering sound effects and is wholly unsuitable for such a task.

It’s an optimization in a physics engine to let objects go to sleep. They can stop being involved in collision checks, constraints, etc. When the active character (your player) is touching something then it can never be inactive because the player can never be inactive (usually). If you are touching something inactive then you can’t be inactive… all of the normal collision stuff needs to apply in case one active object is moving.

I was talking about linear velocity vector not the active function. I already figured out how to make the velocity work for me.

I still get those wild numbers like -6.2436346546E-5 thrown at me. What is weird the same thing happens when moving spatials via the scene editor. Occasionally a strange number pops up on an axis I didn’t even move. Irregardless the number doesn’t affect the position of the spatial. The same applies here. These number seem to be some sort of mathematical anomaly produced by floats.

You do know that number is teeny-tiny near-zero, right?

1 Like

Nope

It’s in exponential form… That’s what the E is. The -5 says to shift the decimal place left 5 places.

So -6.2436346546E-5 is really -0.000062436346546…

…or nearly 0.

3 Likes