Player won’t stop flickering (simple Test based on Beginner Tut)

I wanted to modify the “Hello Collision” Tutorial ( to simply creating my own world instead of using the given town model.

So I inserted a box to represent the floor, and registered it to the physics space.

When I run the project, it will flicker strangely, as if the player was falling or being stuck or something. When I walk around, it will flicker sometimes, and sometimes it won’t, depending on the player’s location. Also, especially when walking right and left, it seems like there are “bumps” on the floor, which should be even.

I have tried various things such as modifiying the player’s parameters, disabling the default input key mappings, etc., but it won’t stop flickering. Any help will be greatly appreciated.

[java]package game;

import java.util.logging.Level;


import com.jme3.asset.TextureKey;

import com.jme3.asset.plugins.ZipLocator;

import com.jme3.bullet.BulletAppState;

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.bullet.util.CollisionShapeFactory;

import com.jme3.input.KeyInput;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.light.AmbientLight;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector2f;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial;

import com.jme3.scene.shape.Box;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.WrapMode;


  • Example 9 - How to make walls and floors solid.
  • This collision code uses Physics and a custom Action Listener.
  • @author normen, with edits by Zathras


    public class HelloCollision extends SimpleApplication

    implements ActionListener {

    // private Spatial sceneModel;

    private BulletAppState bulletAppState;

    // private RigidBodyControl landscape;

    private CharacterControl player;

    private Vector3f walkDirection = new Vector3f();

    private boolean left = false, right = false, up = false, down = false;

    private RigidBodyControl floor_phy;

    private static Box floor;

    private Material floor_mat;

    public static void main(String[] args) {


    HelloCollision app = new HelloCollision();



    public void simpleInitApp() {

    * Set up Physics /

    bulletAppState = new BulletAppState();



    // We re-use the flyby camera for rotation, while positioning is handled by physics

    viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));




    floor_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");


    Texture tex3 = assetManager.loadTexture(key3);


    floor_mat.setTexture("ColorMap", tex3);

    * Initialize the floor geometry /

    floor = new Box(Vector3f.ZERO, 20f, 0.1f, 11f);

    floor.scaleTextureCoordinates(new Vector2f(3, 6));

    Geometry floor_geo = new Geometry("Floor", floor);


    floor_geo.setLocalTranslation(0, -0.1f, 0);


    // Make the floor physical with mass 0.0f!

    floor_phy = new RigidBodyControl(0);



    // We set up collision detection for the player by creating

    // a capsule collision shape and a CharacterControl.

    // The CharacterControl offers extra settings for

    // size, stepheight, jumping, falling, and gravity.

    // We also put the player in its starting position.

    CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);

    player = new CharacterControl(capsuleShape, 0.2f);




    player.setPhysicsLocation(new Vector3f(0, 10, 0));

    // We attach the scene and the player to the rootNode and the physics space,

    // to make them appear in the game world.

    // rootNode.attachChild(sceneModel);

    // bulletAppState.getPhysicsSpace().add(landscape);



    cam.lookAt(new Vector3f(10, 2, 0), Vector3f.UNIT_Y);


    private void setUpLight() {

    // We add light so we see the scene

    AmbientLight al = new AmbientLight();



    DirectionalLight dl = new DirectionalLight();


    dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());



    * We over-write some navigational key mappings here, so we can
  • add physics-controlled walking and jumping: /

    private void setUpKeys() {

    // inputManager.clearMappings();

    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));

    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));

    inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));

    inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));

    inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));

    inputManager.addListener(this, "Left");

    inputManager.addListener(this, "Right");

    inputManager.addListener(this, "Up");

    inputManager.addListener(this, "Down");

    inputManager.addListener(this, "Jump");


    * These are our custom actions triggered by key presses.
  • We do not walk yet, we just keep track of the direction the user pressed. */

    public void onAction(String binding, boolean value, float tpf) {

    if (binding.equals("Left")) {

    if (value) { left = true; } else { left = false; }

    } else if (binding.equals("Right")) {

    if (value) { right = true; } else { right = false; }

    } else if (binding.equals("Up")) {

    if (value) { up = true; } else { up = false; }

    } else if (binding.equals("Down")) {

    if (value) { down = true; } else { down = false; }

    } else if (binding.equals("Jump")) {




  • This is the main event loop–walking happens here.
  • We check in which direction the player is walking by interpreting
  • the camera direction forward (camDir) and to the side (camLeft).
  • The setWalkDirection() command is what lets a physics-controlled player walk.
  • We also make sure here that the camera moves with player.



    public void simpleUpdate(float tpf) {

    Vector3f camDir = cam.getDirection().clone().multLocal(0.15f);

    Vector3f camLeft = cam.getLeft().clone().multLocal(0.1f);

    walkDirection.set(0, 0, 0);

    if (left) { walkDirection.addLocal(camLeft); }

    if (right) { walkDirection.addLocal(camLeft.negate()); }

    if (up) { walkDirection.addLocal(camDir); }

    if (down) { walkDirection.addLocal(camDir.negate()); }