Hi!
I have a little problem with collision! I imported two models .obj (made in blender), the first model is a robot and the second is a house(has a open door).
I'm trying to pass through the door so i can put my robot inside it. The house is using StaticPhysicsNode and the robot is using DynamicPhysicsNode.
My question is if jmonkey physics manage that kind off collision? What should i do to make things go right?
Thanks and sorry about my english!
if (dynamic)
{
((DynamicPhysicsNode)node).setMaterial(Material.IRON);
((DynamicPhysicsNode)node).generatePhysicsGeometry();
((DynamicPhysicsNode)node).computeMass();
((DynamicPhysicsNode)node).setCenterOfMass(new Vector3f( 0f, -2f, 0f ));
final Material playerMaterial = new Material( "player material" );
((DynamicPhysicsNode)node).setMaterial( playerMaterial );
}
else
{
((StaticPhysicsNode)node).setMaterial(Material.DEFAULT);
((StaticPhysicsNode)node).generatePhysicsGeometry(true);
}
So, i managed to get in the house but my problem is different now.
When my dynamic node(character) collides with static node(house) goes wild… hehehe… it don't just collide… it bounce off… what do i have to define so nodes collide without this reaction ??
Someone help, please! I'm going crazy!
Actually because I always had problems with such effects and I was not able to control them stable I quit using Physics (although I sounds so promising!) But nevertheless, have a look in Lesson6 of the tutorial (part of jME-Physics2):
There you have somethin like this:
final SyntheticButton collisionEventHandler = lowerFloor.getCollisionEventHandler();
// we can subscribe for such an event with an input handler of our choice now
input.addAction( new MyCollisionAction(), collisionEventHandler, false );
private class MyCollisionAction extends InputAction {
public void performAction( InputActionEvent evt ) {
// something collided with th lower floor
// we want to put everything that collides with the lower floor up again
// as we know this action is handling collision we can cast the data to ContactInfo
final ContactInfo contactInfo = ( (ContactInfo) evt.getTriggerData() );
DynamicPhysicsNode sphere;
// the contact could be sphere <-> floor or floor <-> sphere
if ( contactInfo.getNode2() instanceof DynamicPhysicsNode ) {
// ok it's floor <-> sphere
sphere = (DynamicPhysicsNode) contactInfo.getNode2();
}
else if ( contactInfo.getNode1() instanceof DynamicPhysicsNode ) {
// ok it's sphere <-> floor
sphere = (DynamicPhysicsNode) contactInfo.getNode1();
}
else {
// no dynamic node - should not happen, but we ignore it
return;
}
// put the sphere back up
sphere.clearDynamics();
sphere.getLocalTranslation().set( 0, 5, 0 );
}
}
Looks for me that you may use this. Maybe calling node.clearDynamics() if the collision (character->wall) occurs.
But that is just a guess...hope I got you in the right direction!
There's a special parameter to disable bounding. Here's a nice material setup for characters:
protected static Material characterMaterial = null;
static {
characterMaterial = new Material( "Character Material" );
characterMaterial.setDensity( 1f );
MutableContactInfo contactDetails = new MutableContactInfo();
contactDetails.setBounce(0);
contactDetails.setMu(1);
contactDetails.setMuOrthogonal(1);
contactDetails.setDampingCoefficient(10);
characterMaterial.putContactHandlingDetails( Material.DEFAULT, contactDetails );
}
Thank you guys for helping me, but my problem continues.
It seems the house(static node) is given back the same force my char(dynamic node) is applying to it when collide…
I uploaded to youtube a video wich demonstrate my problem, its more easy to understend…
http://www.youtube.com/watch?v=yOYZJyI7PgU
Code:
if (dynamic)
{
//characterMaterial = new Material( "Character Material" );
//characterMaterial.setDensity( 1f );
node.generatePhysicsGeometry();
final Material characterMaterial = new Material( "Character Material" );
characterMaterial.setDensity( 1f );
MutableContactInfo contactDetails = new MutableContactInfo();
contactDetails.setBounce(0);
contactDetails.setMu(1);
contactDetails.setMuOrthogonal(1);
contactDetails.setDampingCoefficient(10);
characterMaterial.putContactHandlingDetails( Material.DEFAULT, contactDetails );
((DynamicPhysicsNode)node).setMaterial(characterMaterial);
((DynamicPhysicsNode)node).computeMass();
((DynamicPhysicsNode)node).setCenterOfMass(new Vector3f( 0f, -2f, 0f ));
//((DynamicPhysicsNode)node).setMass(500);
((DynamicPhysicsNode)node).addForce( new Vector3f( 0.0f, 5.0f, 0.0f ) );
FrictionCallback fc = new FrictionCallback();
fc.add((DynamicPhysicsNode)node, 0f, 25.0f);
this.physicsSpace.addToUpdateCallbacks(fc);
}
else
{
((StaticPhysicsNode)node).setMaterial(Material.IRON);
((StaticPhysicsNode)node).generatePhysicsGeometry(true);
}
Thanks guys… my problem is solved.
Actually the problem was in my character controls. Take a look what i was using.
KeyNodeForwardAction forward = new KeyNodeForwardAction(node, 30f);
addAction(forward, "forward", true);
KeyNodeBackwardAction backward = new KeyNodeBackwardAction(node, 15f);
addAction(backward, "backward", true);
Some how this code created that reaction.
Hmm,…as far as I as soon you are using physics you should use only torque and force in order to
move you character. The actions you use are useing the localtranslation(). Actually I did this also
when using physics cause it was the simplest but the freaky sideeffects where (as yours) not to
handle anymore (it had its own live suddenly )
The right way how to control a character with physic, have a look here, but don't expect it to be
simple
http://www.jmonkeyengine.com/forum/index.php?topic=10233.0