Problem with walkDirection: Spatial in air

Hello everyone. I have some problem while using walkDirection() method: spatial flies above the ground, how i can fix it? And one more question : how to rotate collision to viewDirection?

Here is a piece of code:

        if (forw){   pos.addLocal(camDir); }
        if (backw){  pos.addLocal(camDir.negate()); }

        if (left){  pos.addLocal(camLeft);}
        if (right){ pos.addLocal(camLeft.negate());}

        if (jump){if(this.onGround()){ jump(new Vector3f(0, 25, 0)); }}


Extend BetterCharacterControl and override these.

    //Override default collisionshape due to .7 offset.
    protected CollisionShape getShape() {
        float radius = getFinalRadius();
        float height = getFinalHeight();
        float cylinder_height = height - (2.0f * radius);
        CylinderCollisionShape cylinder = new CylinderCollisionShape(
                new Vector3f(radius, cylinder_height / 2f, radius)/*NB constructor want half extents*/, 1);
        SphereCollisionShape sphere = new SphereCollisionShape(getFinalRadius());
        CompoundCollisionShape compoundCollisionShape = new CompoundCollisionShape();
                new Vector3f(0,/*sphere half height*/ radius, 0)); // bottom sphere
                new Vector3f(0,/*half sphere height*/ (radius) +/*cylinder half height*/ (cylinder_height / 2.f), 0)); // cylinder, on top of the bottom sphere
                new Vector3f(0,/*half sphere height*/ (radius) +/*cylinder height*/ (cylinder_height), 0)); // top sphere       
        return compoundCollisionShape;
    //need to overide because we extended BetterCharacterControl
    public PCControl cloneForSpatial(Spatial spatial) {
        try {
            PCControl control = (PCControl) super.clone();
            return control;
        } catch (CloneNotSupportedException ex) {
            throw new RuntimeException("Clone Not Supported", ex);

    //need to override because we extended BetterCharacterControl
    public PCControl jmeClone() {
        try {
            return (PCControl) super.clone();
        } catch (CloneNotSupportedException ex) {
            throw new RuntimeException("Clone Not Supported", ex);

Not sure what you are rotating here, the collisionshape or the spatial.

Rotating the spatial will rotate the collisionshape.

1 Like

Normalize will kill all of that, so it has to be after pos and before mult. That would mean you have a speed of 25m/s resulting.

Flying also sounds like you need a .setY(0f) in the Walk Direction.
Setting the ViewDirection on pos.normalize() (not local!) looks into the walk direction.

or he also might forget about “friction”.

or he might need set gravity properly for BetterCharacterControl.

there could be many reasons. about pos, i see he normalizeLocal it seems fine for me, well i agree its wrong having it at the end or why it is there, but should work anyway, just not related to having Spatial in air imo.