[SOLVED] BetterCharacterControl and Ice ground

I want to make an ice floor which the player could slip on it. The floor code is as follow:

control = new RigidBodyControl(new BoxCollisionShape(new Vector3f(.5f, .5f, .5f)), 0);
control.setFriction(0);

The player has a capsule collision shape and its mass is 70. There is no slipping effect when moving on the ice but when I tried to put a -1 friction for the ice (I know that this is an illegal value) there is a little wrong slipping effect. I tried to change the mass of the floor with zero friction and it was slipping and colliding with the player like an ice block. So how could I make an ice floor that has a zero mass and the player could slip on it?

I have another question:
How could I remove any z-axis physical movement from the BetterCharacterControl and from RigidBodyControl? I want a 2D like physics.

1 Like

Regarding your first question: Perhaps you’re not seeing slippage because (a) the RigidBodyControl is in kinematic mode or (b) the rigid body is damped. Please check those settings.

1 Like

It’s not kinematic I think. It’s a BetterCharacterControl with its default settings, but I have no idea about dumping. Could you give me a resource :grin:.
Thanks very much for your response

1 Like

What’s the value of betterCharacterControl.getRigidBody().getLinearDamping()? If this value is positive, try lowering it to 0.

1 Like

Thanks @sgold the default dumping was 0.9. The first problem solved now :slight_smile: Thanks.

1 Like

For 2-D physics there are doubtless better solutions than Bullet. However, I don’t know of any that are supported in jMonkeyEngine.

The first thing to try would be to add a PhysicsTickListener object to the physics space, and in its physicsTick() method do something like:

   Vector3f tmpV = new Vector3f();
   for (PhysicsCharacter character : space.getCharacterList()) {
        character.getPhysicsLocation(tmpV);
        tmpV.z = 0f;
        character.setPhysicsLocation(tmpV);
        character.getLinearVelocity(tmpV);
        tmpV.z = 0f;
        character.setLinearVelocity(tmpV);
    }
   for (PhysicsRigidBody rigid : space.getRigidBodyList()) {
        rigid.getPhysicsLocation(tmpV);
        tmpV.z = 0f;
        rigid.setPhysicsLocation(tmpV);
        rigid.getLinearVelocity(tmpV);
        tmpV.z = 0f;
        rigid.setLinearVelocity(tmpV);
    }
2 Likes

For purely 2D physics, my guess is that it won’t take you much time to integrate dyn4j with JME. What you will gain is an exponential reduction in complexity and also never having to worry about constantly reclamping your Z, making sure your stuff doesn’t rotate wrong, etc…

If you have no experience with such things then maybe bullet is better “out of the box”.

2 Likes

This worked :slight_smile: thanks for your time. I have tried to stop it with setting z in the walk direction to zero and forgot the internal rigid body completely

I didn’t think that I can use a 2D physics engine with JME :sweat_smile:. This is a good idea I will think about it thanks very much.

1 Like

Others have done it. I’ve even done it. It’s not too bad.

2 Likes

Actually the BCC has all that physicsTick shebang built in with easy to override methods handling all the damping and force applying for the character. I think I put all that info in the javadoc :wink:

6 Likes

wow, its Normen :smiley: you alife!

I found an easier solution to this problem.
Bullet offers a vector factor for linear and angular movements that the velocity will be multiplied with it. We can put Z as zero for linear velocity and zero as an angular factor for producing a 2D like movements for characters.

rigidBody.setLinearFactor(new Vector3f(1, 1, 0));
rigidBody.setAngularFactor(0);
1 Like

It seems a better solution than bullet. However, I found a plugin for it to JME but it doesn’t have a doc. I wonder if dyn4j could be added to the engine in the future so it could have formal documentation and support :slight_smile: .

dyn4j is super simple to use and has a decent documentation as well or at least not a too bad one. You only need to link it to jme, that’s all, no big deal. I did it with the entity component system.
In case you have as well zay-es in place I probably could share that… maybe I will do this on my fprintf.logdown.com blog (and if I find time I will also make a short documentation on the zay-es wiki).

1 Like

Probably not. The engine already has too many things in it.

2 Likes

Well… personally, I’m not on the same page regarding too many things in the engine (although I’m not one of the folks maintaining it, so I arguably haven’t much to say on that front), but since dyn4j is 2D I don’t see it being a good fit in jME core.