Two rigid bodies are stuck together
Posted: Sun Feb 13, 2011 12:29 am
I have two rigid bodies with a single segment shape attached to each. The first is a small 4x4 square with a friction of 0.7 attached to a rigid body with an infinite MoI and mass of 10. The second is a 4x18 rectangle shape attached to a rigid body with infinite MoI and mass of 81. The rectangle shape represents the player and the square represents a generic crate. To jump, I check to see that the velocity on the Y-axis is 0 and if it is I apply an impulse of 6000 to the player’s rigid body at the center of the rigid body. This will shoot the rectangle up just above the crate. At which point I can maneuver left and right by applying a force of 25000 in the direction on the X axis I wish to go at the center of the player’s rigid body.
If I land on the ground, velocity pretty much becomes 0 and I can instantly jump again. If I land on top of the crate however, velocity on the Y-axis does become 0 but applying an impulse does very little to the velocity. It will shoot up to about 0.3 then slowly back down to 0. Applying the impulse over and over again (after the velocity has reached 0 once more) does the same thing but the player’s rigid body doesn't move. I can however, move horizontally along the crate using forces which slowly moves the player off the crate but also pulls the crate with the player until they are no longer touching.
Currently the elasticity for all the shapes in the Space is set to 0.0f. Elasticity values between 0 and 0.9 allow the velocity to reach 0 however values 1.0 and above cause the rigid body to bounce off and when it comes to "rest" on the crate the velocity never reaches 0 but fluctuates between two numbers. The gravity in the Space is set to -200 and damping is set to 0.9, iterations set at 10 and the step is 1.0f/6.0f. The ground segments are attached to the static body of the Space.
The desired behavior is that the player should be able to jump onto crate and jump off of it (i.e. crates being stacked will allow the player to jump onto each crate getting higher and higher). The crate moving along with the player on the x-axis is I suspect due to the low mass of the crate and friction of the ground which is set to 0.5.
I've tried messing around with the elasticity, friction, mass and magnitude of the impulse but as soon as the player rigid body comes to rest on the crate they are inseparable in the vertical axis. When the player's rigid body comes to rest on top of the crate, there is pretty much just a pixel of overlap with the top of the crate, but I would have figured that an impulse of that magnitude (I've gone up to 18000) would seperate the two bodies.
What am I missing?
Edit: I tried applying a force instead of an impulse on the Y-axis and the rigid bodies no longer get stuck on eachother. So I guess the problem lies in my understanding of what an impulse is. Isn't an Impulse a force applied over time? So an impulse of 1000 might be a force of 500 applied over 2 seconds or a force of 200 applied over 5 seconds? At any rate, an impulse seems to be greater than a force so why can't it break the "bonds" between the two rigid bodies?
Edit #2: I spoke too soon. I can seperate the two rigid bodies with a force or an impulse but only if I remove the restriction of being able to apply said force/impulse when the velocity in the Y-axis is zero. So, a continous force/impulse is always able to seperate the two bodies but a single force/impulse (doesn't seem to matter at what magnitude) cannot seperate them.
If I land on the ground, velocity pretty much becomes 0 and I can instantly jump again. If I land on top of the crate however, velocity on the Y-axis does become 0 but applying an impulse does very little to the velocity. It will shoot up to about 0.3 then slowly back down to 0. Applying the impulse over and over again (after the velocity has reached 0 once more) does the same thing but the player’s rigid body doesn't move. I can however, move horizontally along the crate using forces which slowly moves the player off the crate but also pulls the crate with the player until they are no longer touching.
Currently the elasticity for all the shapes in the Space is set to 0.0f. Elasticity values between 0 and 0.9 allow the velocity to reach 0 however values 1.0 and above cause the rigid body to bounce off and when it comes to "rest" on the crate the velocity never reaches 0 but fluctuates between two numbers. The gravity in the Space is set to -200 and damping is set to 0.9, iterations set at 10 and the step is 1.0f/6.0f. The ground segments are attached to the static body of the Space.
The desired behavior is that the player should be able to jump onto crate and jump off of it (i.e. crates being stacked will allow the player to jump onto each crate getting higher and higher). The crate moving along with the player on the x-axis is I suspect due to the low mass of the crate and friction of the ground which is set to 0.5.
I've tried messing around with the elasticity, friction, mass and magnitude of the impulse but as soon as the player rigid body comes to rest on the crate they are inseparable in the vertical axis. When the player's rigid body comes to rest on top of the crate, there is pretty much just a pixel of overlap with the top of the crate, but I would have figured that an impulse of that magnitude (I've gone up to 18000) would seperate the two bodies.
What am I missing?
Edit: I tried applying a force instead of an impulse on the Y-axis and the rigid bodies no longer get stuck on eachother. So I guess the problem lies in my understanding of what an impulse is. Isn't an Impulse a force applied over time? So an impulse of 1000 might be a force of 500 applied over 2 seconds or a force of 200 applied over 5 seconds? At any rate, an impulse seems to be greater than a force so why can't it break the "bonds" between the two rigid bodies?
Edit #2: I spoke too soon. I can seperate the two rigid bodies with a force or an impulse but only if I remove the restriction of being able to apply said force/impulse when the velocity in the Y-axis is zero. So, a continous force/impulse is always able to seperate the two bodies but a single force/impulse (doesn't seem to matter at what magnitude) cannot seperate them.