Trouble with collisions

Hello everybody.

First of all, english is not my mother tongue. I know that i’ll do a lot of errors, but it’s very late here. don’t be angry for that, i don’t do it on purpose.

Some month ago, i tried to make a game with a strange gravity. That was the point. I started to do it using lwjgl and it was not bad, but collisions was too terrible for me. In this game, the gravity can change, you can walk on the wall or on the plafond etc.

After that, i started to use jmonkeyengine, and it was pretty cool to find the jbullet in it. But, when i tried to make the gravity negative, i founded a problem. When my objet collide with the object above it, my objet just “warp” bottom, then “fall to the sky” again, collide, warp and so on.

I created a code, then you can check if you have the same problem:


package mygame.test;


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.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.Mesh;

import com.jme3.scene.Node;

import com.jme3.scene.shape.Box;

import com.jme3.scene.shape.Cylinder;



  • @author Bubuche


    public class SampleBugCollision extends SimpleApplication


    public static void main(String args[])


    SampleBugCollision sbc = new SampleBugCollision();




    public void simpleInitApp()


    init physics, as we need it /

    BulletAppState bas = new BulletAppState();


    create a node with bottom-to-up gravity /

    Mesh sample_mesh = new Cylinder(10, 10, 0.5f, 1, true);

    Geometry geom = new Geometry(“SampleGeometry”, sample_mesh);

    Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

    mat.setColor(“Color”, ColorRGBA.Blue);


    Node sample = new Node(“sample”);

    CollisionShape cs = new CapsuleCollisionShape(0.5f, 1);

    CharacterControl cc = new CharacterControl(cs, 1f);

    this line change the gravity /




    create a ground above the “sample” /

    Box ground = new Box(Vector3f.ZERO, 3, 1, 3);

    Geometry ground_geom = new Geometry(“GroundGeometry”, ground);

    Material ground_mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

    ground_mat.setColor(“Color”, ColorRGBA.Green);


    CollisionShape ground_cs = new BoxCollisionShape(new Vector3f(3, 1, 3));

    define the control for the ground. Solid, with a 0 mass, so don’t move when hit */

    RigidBodyControl rbc = new RigidBodyControl(ground_cs, 0);


    rbc.setPhysicsLocation(new Vector3f(0, 5, 0));








    i tried to make it as short and as clear as possible. It’s :

    create an object with a negative gravity.

    create something above it.


    This problem happen with CharacterControl only, not with RigidBodyControl. But then, i don’t have a “walk” method. I still can apply a force and use a ball, but then, i have an other problem: if i attache the camera with a cameranode (what i plan to do), the camera will roll too. I didn’t find a good way to attach a node (A) to the position of an other node (B), but without the the rotation (locale) of the node B. I can still take the rotation of B, revert it, and apply this to A, and this each frame, but i think that there is a more clean way to do it.

    Anyway, is there a way to fix the bug of the “warping” object ? ← this is the point of the topic

    If no, do you have a suggestion to have a good “any-gravity+good-collision” control ?

    P.S.: i thought i made a topic on that already, but i don’t found my account (this is a new one) or the post. So, i am maybe wrong when i think i have did it before.

I think your supposed to set the gravity after attaching it to the physics space

i just tried it right now (after seeing what you wrote). The result is exactly the same. I can post the code again (with the change) but it’s only cut


and paste it at the very end of the method.

Did you try the code ? Maybe i am the only one with the problem.

Thx anyway.

no i didn’t try it and i’ve never tried modifying the gravity of a character controller before, i guess theres an issue with it? idk. Maybe post some before and after screenshots.

i want to put a “up” on this. Actually, i can post screenshot of that, but as long as it’s a “warp” problem, you’ll just see 2 pictures without any problems - you can imagine that the objet warped from the first position to the second, but it’s not really interesting.

I just posted the code (even if i don’t know why it’s all gree-for-comment) and it just reproduce the bug 100% times. I also realized that i didn’t remove the package (mine) but i think that it’s not a big deal (i can but … humm, anyway, you’ll have to put your own).

This code just reproduce the bug, it’s way better than any screenshot.

I keep working on the rest of my game (and i’ll have some questions about otpimization later - not now). But if i can’t find a solution for this problème, it’ll just be useless.

+i am more and more thinking that a custom rigidbodycontrol would be good (even if it creates other problems).

I think i’ll have a look into the source code of the charactercontrol, but it’s definitively not something that i want to do.

well i tried your test case, and made some progress by adjusting settings. Cube size, step height, gravity strength and other character control settings. And it worked to some extent, but it would always seep into the cube, which was strange.

So I’m not sure.

There are bullet forums, you can try those, else look for alternative ways to implement such behavior

Hello, it’s me, again.

I didn’t solve the problem with the negative gravity + charactercontrol. So, i did something to have what i wanted, and i’ll try to explain what i did here. Maybe it’s ugly, but it works (even if i still need to tweak some settings).

  • the physic of the char is a sphere (sphere collision) + rigidbodycontrol. The rigidbodycontrol has a "setGravity" method which take a Vector3f (instead a float, so i can make gravity for every directions). The problem was : if i attach a node to the ball (for the camera for instance) the node will "roll" with the ball.

  • To solve this problem, i just created a control which "cancel" the rotation on the spatial. For exemple, you have a sphere A. Then, create a Node B, and attach it to A. Then, add the "invert rotation control" to B. This control always look at the "getLocalRotation" of the parent (here: A) invert it and apply the result to B as a localrotation. So, if the node B is just in the center of the sphere, he won't move when the sphere will roll. But, if B is not in the center, he will juste turn around the sphere (but will keep the "0-rotation"). An other problem is that this control "take" the "localrotation", so you can't use it yourself. For exemple, a lot of people could want to use this localrotation to move the camera or whatever. As the control "0-rotation" use this parameter, it's a bit a problem

  • to solve this new problem, i just add a node to B. So, i can rotate it as i want, and i can move it away from the center without having the "turn around" effect.
  • .

So, to make a long story short:

A => a sphere (with the physic control).
B => a node, attach to the center of A, with a control to cancel the rotation of B (B don't rotate in regard of the parent of A).
C => a node attach to B, to allow rotation (independant of the rotation of A, of course).

and now, i am thinking about add an other node to handle the gravity. I mean : in a game, when gravity change, the camera must "turn". If i add a node for that, i won't have to perform myself the combination of the current user rotation of the camera (where the camera is poiting after the user look around) and the rotation due to the gravity.

Is it a good idea to skack nodes like that ?

About the charactercontrol's bug, if you replace the collisionshape by a cube (not a capsule) the bug is less here (but still here). I am still working on it.