BetterCharacterControl flickering problem [SOLVED]

Hello guys,

I’m developing my Voxel Based game and i’m facing a strange issue: When I move my player with BetterCharacterControl it walks more then what is specified when i’m loading some chunks, even using tpf, as you can see on video below:

The code where I move the character is this:

    @Override
    protected void controlUpdate(float tpf) {
	camDir.set(0, 0, 1); //For debug i'm just walking along Z axis.
	walkDir.set(0, 0, 0);

	if (backFront > 0) {
	    walkDir.addLocal(camDir.negate());
	} else if (backFront < 0) {
	    walkDir.addLocal(camDir);
	}

	walkDir.multLocal(200f * tpf);
	playerControl.setWalkDirection(walkDir);
	if (jump && playerControl.isOnGround()) {
	    playerControl.jump();
	}
	backFront = 0;
	jump = false;
    }

I know this is caused by the low frame rate instant, but as far as I know, the walkDir.multLocal(200f * tpf); should do the trick. What i’m missing?

Uh… I could be wrong but I thought walkdir already internally took tpf into account. So multiplying it again will cause super-variation.

…given the implication that you are trying to have your character walk at 200 meters per second, it’s a pretty good clue.

But again, I’ve never used the control and that setDirection() method is already misnamed because it’s not really setting direction.

1 Like

Mann!!! :stuck_out_tongue_closed_eyes: It worked like a charm! Aparently, BetterCharacterControl uses tpf internally. I’ll confirm to be sure. My desired walking speed is 2 meters, so removing the tpf and setting move speed to 2f solved it :grin:

walkDir.multLocal(2f);

Now I ask to myself: Where I got this 200* tpf? :hushed:

Anyway, for future reference of visitors:

@Override
protected void controlUpdate(float tpf) {
    camDir.set(0, 0, 1); //For debug i'm just walking along Z axis.
    walkDir.set(0, 0, 0);

    if (backFront > 0) {
        walkDir.addLocal(camDir.negate());
    } else if (backFront < 0) {
        walkDir.addLocal(camDir);
    }

    walkDir.multLocal(2f);
    playerControl.setWalkDirection(walkDir);
    if (jump && playerControl.isOnGround()) {
        playerControl.jump();
    }
    backFront = 0;
    jump = false;
}
1 Like