Character keeps falling through floor

I have a spatial, and a floor made of segment class instances, containing standard Box, but the character keeps falling through the floor if I use CharacterControl.setWalkDirection(). Using another Box object that’s not in a segment class works fine.

This is the segment class
[java]
public class StraightSegment
{
private Box box;
private Geometry geomBox;
private Material mat;
private Vector3f nextStartPosition, nextDirection;
public StraightSegment(float x, float y, float z, Vector3f direction)
{
box = new Box(new Vector3f(x, y, z).add(direction.mult(10)), 2.5f + FastMath.abs((direction.x * 3 * 2.5f)), 0.5f, 2.5f + FastMath.abs((direction.z * 3 * 2.5f)));
geomBox = new Geometry(“Box”, box);
mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setColor(“Color”, ColorRGBA.Red);
geomBox.setMaterial(mat);
rootNode.attachChild(geomBox);
nextStartPosition = new Vector3f(x, y, z).add(direction.mult(20));
nextDirection = new Vector3f(direction);

        geomBox.addControl(new RigidBodyControl(0)); 
        bullet.getPhysicsSpace().addAll(geomBox);
    }
    public Vector3f getNextStartPosition()
    {
        return nextStartPosition;
    }
    public Vector3f getNextDirection()
    {
        return nextDirection;
    }
    public void delete()
    {
        rootNode.detachChild(geomBox);
    }
}

[/java]

This is where I call the constructor to create the object, in simpleInitApp
[java]
segments.add(new StraightSegment(0, 0, 0, new Vector3f(0, 0, -1)));
[/java]

This is where I create the character
[java]
public void initRunner()
{
runner = assetManager.loadModel(“Models/Sinbad/Sinbad.mesh.xml”); /* loads model for spatial*/
runner.scale(0.2f,0.2f,0.2f); /* sets spatial scale */
runner.setLocalTranslation(0,15.5f,-1);
runner.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.PI,new Vector3f(0,1,0)));

    runner_direction = new Vector3f(0, 0, -1);
    //runner_speed = 20;
    
    control = runner.getControl(AnimControl.class);
    control.addListener(animListener);
    
    channel = control.createChannel();
    channel.setAnim("RunBase");
    
    capsule = new CapsuleCollisionShape(0.7f,0.5f);
    runnerCC = new CharacterControl(capsule,0);
    runner.addControl(runnerCC);
    bullet.getPhysicsSpace().addAll(runner);
   
    
    rootNode.attachChild(runner);
    
}

[/java]

And the code in simpleUpdate that causes the character to fall straight through the floor
[java]
runnerCC.setWalkDirection(runner_direction);
[/java]

The declarations :
[java]
private AnimChannel channel;
private AnimControl control;
private ArrayList<Object> segments;
private BulletAppState bullet;
private CapsuleCollisionShape capsule;
private CharacterControl runnerCC;
private ChaseCamera chaseCam;
private DirectionalLight sun;
private Spatial runner;
private Vector3f runner_direction, camDir, camLeft;
[/java]

Did you notice in the SDK that the box constructor you use has a line drawn through it indicating that it’s deprecated?

This is because it’s almost never correct to move the box mesh. You really want to be moving the Geometry. I’m not sure if it’s related to your problem but it’s certainly going to cause you problems at some point.

Also the way you calculate the box’s size seems a little suspect. What is it that you are trying to accomplish? Do you have a picture?

I’m not sure what you meant by moving the box mesh?

I’m trying to create an auto-generated path, thereby using segments and generating them as needed, and calculating the position of a segment based on the position of the previous segment.

You are passing the location of the box on the constructor. This physically puts the points in the box mesh at weird locations and makes the Geometry very strange. You should let the box mesh stay at 0,0,0 and then move the Geometry instead. Otherwise you end up with extremely strange bounding shapes.

That’s why that constructor is deprecated because it confuses new users. That’s why it has a big line through it in the SDK code editor and if you hovered over it then it would say it’s deprecated. This is an indicator that you should not use it.

I changed the code to set the Box at Vector3f.ZERO, and move the geometry instead. It works. Thank you very much