Player character with gravity towards -Z and using cylinder instead of capsule

Hello.

I’ve followed tutorials but there’s 2 problems I can’t figure out or where to look from here…


  1. how to use a cylinder instead of capsule? Cylinder would work just fine for my player as surface is flat.

    I get this:

    java.lang.UnsupportedOperationException: Kinematic character nodes cannot have mesh collision shapes

    [java]

    player = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);

    playerBody = new CylinderCollisionShape();

    playerControl = new CharacterControl(playerBody, 0);

    player.addControl(playerControl);[/java]

    From tutorials I would image the CharacterControl creates shape as dynamic by default and cylinder is described as non-mesh… so I don’t get this error message at all.


  2. since I’m using capsule now, how can I rotate it so it stretches on Z axis? In my game world Z is the up, not Y.I’ve found the setViewDirection(), but that rotates the spatial, not the collision shape.



    2.1. Also, shape falls towards -Y, even if I set gravity of the system towards -Z…



    [java] bulletAppState = new BulletAppState();

    stateManager.attach(bulletAppState);

    bulletAppState.getPhysicsSpace().setGravity(Vector3f.UNIT_Z.negate().multLocal(9.81f));

    bulletAppState.getPhysicsSpace().enableDebug(assetManager);

    player = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);



    //playerBody = new CylinderCollisionShape();

    playerBody = new CapsuleCollisionShape(60f, 140f);

    playerControl = new CharacterControl(playerBody, 0);

    player.addControl(playerControl);



    player.setLocalScale(27f);

    player.lookAt(Vector3f.UNIT_Y, Vector3f.UNIT_Z); // this doesn’t apply if I do physics

    ControlMovable movable = new ControlMovable(); // where walkDirection is set for movement

    movable.setMaxMoveSpeed(300);

    player.addControl(movable);



    bulletAppState.getPhysicsSpace().add(player);

    rootNode.attachChild(player);[/java]



    Thank you for your help.

Why is yours z-up? Jme is y-up and you will constantly run into issues if you don’t switch.

@Sploreg said:
Why is yours z-up? Jme is y-up and you will constantly run into issues if you don't switch.


My game logic is 2d and it's more natural for me to think in (x,y) then (x, z). Yes I'll have to do some extra lines for rotation but I don't mind.
Still, you have to transform the shapes somehow.. like what if your character goes prone, capsule must lay down on the floor somehow to accommodate.

It’s not just a matter of transforming to be z-up, some tools and items in the SDK are designed y-up and you won’t be able to just transform them (such as terrain).

@Sploreg

Ok I’ll go back to Y up rather then fight the system all the way.



So, does anybody know answers for:

  1. how to use a cylinder instead of capsule?
  2. how do you transform/rotate the collision shapes?
  3. why is shape falling to -Y and not towards gravity I set to be -Z?

What? A cylinder shape doesn’t work? o.O

Is there a specific reason to use a cylinder over a capsule? Unless you have a real need for different characteristics then sticking with the “standard” will generally give better results…and even though right now your game might be flat you never know when you are going to want to add a step or a slope or something.

@zarch, but still - aren’t cylinder collision shapes supposed to work with a CharacterControl?

@memonick said:
@zarch, but still - aren't cylinder collision shapes supposed to work with a CharacterControl?

sure they do

Thought so. Then what’s Kova’s problem? I can’t see a problem in his code.