Hi all,
when I apply torque to a physicsnode which is a cube, it starts rotating, but rotation never seems to stop even if the cube is rolling over the floor object. Is this normal, and do you guys have an idea how to stop the cube rotating by time? (something like rotation dumping)
I want my cube stopping its rotation when rolling over the floor object (it is actually touching the floor, so I was expecting the floor to stop its rotation by time). how can I achieve this?
Thanks in advance!
Edit: tried to restate the problem in a more clear way
I'd have to see how you're applying torque, and it would also help to know which physics implementaiton you're using. The big thing to double-check is friction. Make sure all the bodies you're working with have friction coefficients defined appropriately for their materials. Without it, all you have acting against the movement of your body is gravity, which means that the torque applied to your object through its collision with the floor needs to overcome the torque you're applying in code.
Can you post the implementation you're using, the torque you're applying, the mass and dimensions of the cube, and your gravitational acceleration?
Also, are you applying a CONSTANT torque? Or just one burst?
-Falken
you can also use a com.jmex.physics.callback.FrictionCallback to add additional friction.
Hi Falken,
I apply the force with an input controller, so when I press Home key, I apply the torque with line
public class ApplyForceInputAction extends InputAction {
DynamicPhysicsNode node;
public ApplyForceInputAction(DynamicPhysicsNode node){
this.node = node;
}
@Override
public void performAction(InputActionEvent evt) {
node.addTorque(new Vector3f(10000, 0, 0));
}
}
And I attach my input handler like this:
if (dynamicNode != null)
input.addAction(new ApplyForceInputAction(dynamicNode),
InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_END, InputHandler.AXIS_NONE,
false);
When my object (which is a cube) falls on to ground, I press home key a couple of times so that it starts rotating, after some time, object transfers its rotational speed to linear speeds and starts covering some distance. The problem is that, it never stops. Here are the material definitions for base object and falling object (cube)
Here’s the falling object’s definition
Material customMaterial = new Material(“test”);
customMaterial.setDensity(3f);
MutableContactInfo info = new MutableContactInfo();
info.setBounce(0.0f);
info.setMu(0.1f);
info.setMuOrthogonal(300f);
customMaterial.putContactHandlingDetails(Material.DEFAULT, info);
dynamicNode.setMaterial(customMaterial);
dynamicNode.computeMass();
This is the base object
PhysicsNode sNode = getPhysicsSpace().createStaticNode();
getSceneNode().attachChild(sNode);
sNode.attachChild(createBase());
sNode.generatePhysicsGeometry();
There is one assumption here, that the base object will have default material applied. I am checking with a different material now! God I did not think about this before
I can send you the whole project if you want to have a look at it. Cheers
Nope, setting materials to both object did not stop the rotating box to stop
Here is the physics engine used according to logs:
INFO: Found physics implementation 'ODE' (ODEJava version 0.3.1).
…
…
INFO: Creating PhysicsSpace using physics implementation 'ODE'.
Oct 22, 2009 8:25:39 PM com.jmex.physics.impl.ode.OdePhysicsSpace setUpdateRate
INFO: Changed the number of updates in a second of PhysicsWorld to: 100.0
Oct 22, 2009 8:25:39 PM com.jmex.physics.impl.ode.OdePhysicsSpace setStepSize
INFO: Setting StepSize of PhysicsWorld to : 0.01
Oct 22, 2009 8:25:39 PM com.jmex.physics.impl.ode.OdePhysicsSpace setDirectionalGravity
INFO: Setting Gravity of PhysicsWorld to: (0.0, -9.8, 0.0)
A primitive dampening would be to get the current AngularVelocity and set it as the new one multiplicated with something like 0.95f. May not resolve the reason for the rotating, but might fix it anyway.
Empire thanks for the reply there,
I also thought that applying a reverse force or modifying the angular velocity may help, but since the rolling object is a cube, I need to find the exact moment to stop the cube rotating so that it rests on the floor on its base instead of an awkward angle touching the ground.
And also I have no idea how it can happen, but if I stop the cube by applying reverse torque or setting angular velocity to zero, and even if the cube is not resting at an angle of 0 (it is standing on one of its edges instead of on one of it's faces), it just continues staying like that :?. In a normal physical world, I expect the cube to some to a resting stance resting on one of its faces. I think I need to learn more about the physics library
oramia . . . any chance you could point me at the project? I'm curious to have a look at your code.
-Falken