Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to walk stairs and slopes?

We use jme3 and a problem with the BetterCharacterControl is that setMaxSlope is not implemented. The developer of the engine says that we can solve it ourselves using the new controller:

http://hub.jmonkeyengine.org/forum/topic/setmaxslope-for-bettercharactercontrol/

And I would really like a solution since my game needs it. I asked about it before but we didn't solve it:

How to improve character control for my 3D game?

Can you help us progress? I've recorded a video with the problem:

http://www.youtube.com/watch?v=PF_UzoOXD0E

Some documentation is here: http://hub.jmonkeyengine.org/wiki/doku.php/jme3:advanced:walking_character?s[]=bettercharactercontrol#bettercharactercontrol

My effort to add the functionality to the controller:

package adventure;

import com.jme3.math.Vector3f;
import com.jme3.bullet.control.BetterCharacterControl;

public class GameCharControl extends BetterCharacterControl {
    protected Vector3f lastlocation = new Vector3f();

    public GameCharControl(float x, float y, float z) {
        super(x, y, z);
    }

    @Override
    public void update(float tpf) {
        super.update(tpf);
        System.out.println("location " + location);
        System.out.println("lastlocation " + lastlocation);

        if (location.equals(lastlocation)) {
            System.out.println("update2");
            this.setHeightPercent(101);
        }
        rigidBody.getPhysicsLocation(location);
        applyPhysicsTransform(location, rotation);
        lastlocation = location;
    }
}

But the above is not making any change or if I set height to 101 then it gets difficult to move for the game character. Can you help us see what should be done?

like image 311
Niklas Rosencrantz Avatar asked Oct 03 '22 02:10

Niklas Rosencrantz


2 Answers

Since movement treats the character as a PhysicsRigidBody made of PhysicsJoints, there probably isn't enough upward oomph in his leg or knee. Hopefully the parameters there just weren't set up to accommodate that size of stair.

Since you had the most trouble with navigating an angled stair, a secondary measure might be to adjust the walk direction. I doubt you can rely on location.equals(lastlocation) but within a short distance is a good check to see if the character ran into an obstacle. Once you know there is a step you want to scale it cleanly or stay stuck below.

like image 112
clwhisk Avatar answered Oct 07 '22 19:10

clwhisk


Why not use KinematicCharacterController which has setMaxSlope implemented?

Not sure which JME you are using, but here's the source to that controller:

https://code.google.com/p/jbullet-jme/source/browse/branches/jbullet/src/com/bulletphysics/dynamics/character/KinematicCharacterController.java

like image 42
ClickerMonkey Avatar answered Oct 07 '22 18:10

ClickerMonkey