Hi everyone,
I’m new to JME and I read yesterday all beginner tutorials. So far so good… My goal for today is creating a own simple World. So having a “Box” as a floor and some simple geometric Figures at this world.
And at this point I got a problem: player.jump() works only rarely. So I make some debug print in the System console in the simpleUpdate Method:
[java]System.out.println(player.onGround());[/java]
And in ca. 90% it returns false, although I definitely stand on the ground.
Here are some relevant Code Snippets:
[java] // Creating floor:
Box floor = new Box(Vector3f.ZERO, worldSize, .1f, worldSize);
floor.scaleTextureCoordinates(new Vector2f(12, 24));
Geometry floorGeom = new Geometry(“floor”, floor);
Material floorMat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
floorMat.setColor(“m_Color”, ColorRGBA.White);
Texture floorTexture = assetManager.loadTexture(“Textures/Terrain/Pond/Pond.png”);
floorTexture.setWrap(Texture.WrapMode.Repeat);
floorMat.setTexture(“ColorMap”, floorTexture);
floorGeom.setMaterial(floorMat);
floorGeom.setLocalTranslation(0, -0.1f, 0);
floorGeom.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().add(floorGeom);
rootNode.attachChild(floorGeom);[/java]
[java]// Set up player:
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
player.setPhysicsLocation(new Vector3f(0, 10, 0));
bulletAppState.getPhysicsSpace().add(player);[/java]
[java] private static ActionListener actionListener = new ActionListener() {
public void onAction(String binding, boolean keyPressed, float tpf) {
if (binding.equals(“Left”)) {
left = keyPressed;
} else if (binding.equals(“Right”)) {
right = keyPressed;
} else if (binding.equals(“Up”)) {
up = keyPressed;
} else if (binding.equals(“Down”)) {
down = keyPressed;
} else if (binding.equals(“Jump”) && keyPressed) {
player.jump();
}
}
};[/java]
It would be very nice if somebody could help me… I’m sitting here ca. 3 hours and googled for any solution - but somehow without success.
Thanks.
Hi again,
well, I resolved the problem.
I replaced
[java] // Creating floor:
Box floor = new Box(Vector3f.ZERO, worldSize, .1f, worldSize);
floor.scaleTextureCoordinates(new Vector2f(12, 24));
Geometry floorGeom = new Geometry("floor", floor);
Material floorMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
floorMat.setColor("m_Color", ColorRGBA.White);
Texture floorTexture = assetManager.loadTexture("Textures/Terrain/Pond/Pond.png");
floorTexture.setWrap(Texture.WrapMode.Repeat);
floorMat.setTexture("ColorMap", floorTexture);
floorGeom.setMaterial(floorMat);
floorGeom.setLocalTranslation(0, -0.1f, 0);
floorGeom.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().add(floorGeom);
rootNode.attachChild(floorGeom);[/java]
with (i found this code in a JME-Example):
[java] Material material = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Box floorBox = new Box(140, 0.25f, 140);
Geometry floorGeometry = new Geometry("Floor", floorBox);
floorGeometry.setMaterial(material);
floorGeometry.setLocalTranslation(0, -5, 0);
// Plane plane = new Plane();
// plane.setOriginNormal(new Vector3f(0, 0.25f, 0), Vector3f.UNIT_Y);
// floorGeometry.addControl(new RigidBodyControl(new PlaneCollisionShape(plane), 0));
floorGeometry.addControl(new RigidBodyControl(0));
rootNode.attachChild(floorGeometry);
bulletAppState.getPhysicsSpace().add(floorGeometry);[/java]
I have no idea why this works better than my version… Has anybody an idea?