But with charactercollision (no, it's not about fall through the ground)

Hello everybody and happy new year.

I met something that for me is a bug. I want to have your opinion about it.

When i charactercontrol “hit” an item with a rigidbodycontrol with a mass > 0, is it normal that the rigidbodycontrol moves ?
For me, the answer is no : only something with a mass should be able to move an other thing with a mass.

And i think that it’s a bug also because no matter if the mass of the rigidbodycontrol is 0.01f or 100f the movement will be the same.

Here is a test case. It’s a bit long but basically it’s :

create a ground (mass 0)
create a ball (mass 100 or whatever)
create a charactercontrol.
animate the charactercontrol.

[java]
package mygame.test;

import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;

/**
*

  • @author Bubuche
    */
    public class TestBugInertie extends SimpleApplication
    {

private CharacterControl control;
private BulletAppState bulletAppState;

public static void main(String[] args)
{
TestBugInertie app = new TestBugInertie();
app.start();
}

@Override
public void simpleInitApp()
{
/*enable physic */
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);

flyCam.setMoveSpeed(5);
bulletAppState.getPhysicsSpace().enableDebug(assetManager);

createCharacter();
createImmobileBall();
createGround();

}

@Override
public void simpleUpdate(float tpf)
{
super.simpleUpdate(tpf);

control.setWalkDirection(Vector3f.UNIT_X.mult(-tpf));

}

private void createCharacter()
{
Node character = new Node(“character”);

Sphere b = new Sphere(10, 10, 0.5f);
Geometry geom = new Geometry("geom_character", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Yellow);
geom.setMaterial(mat);

character.attachChild(geom);

CollisionShape cs = new CapsuleCollisionShape(0.3f, 2f);
control = new CharacterControl(cs, 0.2f);
character.addControl(control);

control.setPhysicsLocation(new Vector3f(3, 1, 0));

rootNode.attachChild(character);
bulletAppState.getPhysicsSpace().add(control);

}

private void createImmobileBall()
{
Node ball = new Node(“ball”);

Sphere b = new Sphere(10, 10, 0.5f);
Geometry geom = new Geometry("geom_ball", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);

ball.attachChild(geom);

CollisionShape cs = new SphereCollisionShape(0.5f);
RigidBodyControl rbc = new RigidBodyControl(cs, 100f);
ball.addControl(rbc);

rbc.setPhysicsLocation(new Vector3f(-2, 1, 0));

rootNode.attachChild(ball);
bulletAppState.getPhysicsSpace().add(rbc);

}

private void createGround()
{
Box b = new Box(Vector3f.ZERO, 4f, 0.2f, 3f);
Geometry geom = new Geometry(“ground”, b);

Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Green);
geom.setMaterial(mat);

CollisionShape cs = new BoxCollisionShape(new Vector3f(4, 0.2f, 3f));
RigidBodyControl rbc = new RigidBodyControl(cs, 0);

geom.addControl(rbc);

rootNode.attachChild(geom);
bulletAppState.getPhysicsSpace().add(rbc);

}
}
[/java]

You should be able to copy and past it.

I am waiting for your feeback and also if you have a solution for this “bug” it will be nice.

While i am here, i ask an other question : is it a good idea to use collisiongroups for gameplay (to let the player “open a door” by making the door non-collidable with it, and to do some puzzle with that, like having some color (one color per group for exemple) to do some puzzles) ?

It moves objects, yes. This can happen when it moves into an object during one frame, it will push it back that bit it penetrated the next frame. Collision groups are very flexible as you have collision groups and collide with groups.

Thanks for the first answer.

For the second, my question is not really “is it possible to do that” but more “is it safe to do that”.

I read that collision groups was here for performance issues. I can compare this to the “culling” system. If someone base all this game on the culling system, i think that it’s not safe as the optimisation can change tomorrow and if some graphic card just disable culling (casue it can do better thing to optimize) the game will be broken.
A game (or even just an application) should rely on something that it is not designed to be “used”. Culling is not (in my mind) a way to remove object from the scene, some people should have the right to turn off the culling system without breaking my game.

The same thing here : i can use collision groups as a feature that is suppose to be used, but i fear a little that tomorrow this optimization will no longer be here (or not under our control, fully controled by some drivers) and my game will be broken.

But thank you for your answers. I’ll try to solve this problem with jbullet, but the more i have to deal with it, the more i find that it’s not a very reliable physic engine. It’s always small flaws (going through the wall if the squad is too big, push object cause we go in them during a frame, warp when the gravity is set to negative and the player encounter a collision, go through the ground when the charactercontrol is hit on the top … ) but when i sum them … ok, i fear that i’ll encounter a lot of new bugs when i’ll play with these collisiongroups :smiley:

Did you work with physics engines yet? Its mostly your fault when it goes awkward, as in all computing. Theres not many known bugs in jbullet apart from sweep tests.