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]