Hi friends
I ran to an strange issue. Issue illustrated in this video :
Anyone had such issue ?
Any hint on what may cause this problem ? Any hint is much appreciated.
- I do not call warp() method on BetterCharacterControl in update loop.
- Tested both with native bullet and jbullet.
I am putting relevant code here :
this is a control, and in update loop I am calling setViewDirection(direction);
which is on my GameCharacterControl.
@Override
protected void controlUpdate(float tpf) {
this.tpf=tpf;
viewDirectionUpdateInterval += tpf;
if (viewDirectionUpdateInterval > 1) {
viewDirectionUpdateInterval = 0;
for (int i = 0; i < grid.getQuantity(); i++) {
if (controls[i] != null) {
Vector3f gridTranslation = grid.getChild(i).getWorldTranslation();
Vector3f spatialTranslation = controls[i].getWorldTranslation();
gridTranslation.y = 0;
spatialTranslation.y = 0;
Vector3f viewDirection = gridTranslation.subtract(spatialTranslation);
controls[i].setViewDirection(new Vector3f(viewDirection));
}
}
}
}
GameCharcterControl class:
here is where i am setting up BetterCharacterControl:
@Override
public void setSpatial(Spatial spatial) {
super.setSpatial(spatial);
// Example:
if (spatial != null){
character=spatial;
characterControl = new BetterCharacterControl(2f,3.5f,75);//TODO : Get measures as user data.
characterControl.setJumpForce(new Vector3f(0, 300,0 ));//TODO : Get measures as user data.
characterControl.setGravity(normalGravity);
character.addControl(characterControl);
characterAnimControl=new CharacterAnimControl();
character.addControl(characterAnimControl);
}
And setViewDirection() method on my GameCharacterControl :
public void setViewDirection(Vector3f viewDirection){
// this.viewDirection.set(viewDirection);
viewDirection.y=0;
viewDirection.normalizeLocal();
//BetterCharacterControl
characterControl.setViewDirection(viewDirection);
Vector3f modelForwardDir = character.getWorldRotation().mult(Vector3f.UNIT_Z);
Vector3f modelLeftDir = character.getWorldRotation().mult(Vector3f.UNIT_X);
// WalkDirection is global!
// You *can* make your character fly with this.
walkDirection.set(0, 0, 0);
if (left) {
walkDirection.addLocal(modelLeftDir.mult(walkSpeed+tpf));
} else if (right) {
walkDirection.addLocal(modelLeftDir.negate().multLocal(walkSpeed+tpf));
}
if (forward) {
walkDirection.addLocal(modelForwardDir.mult(walkSpeed+tpf));
} else if (backward) {
walkDirection.addLocal(modelForwardDir.negate().multLocal(walkSpeed+tpf));
}
//BetterCharacterControl
characterControl.setWalkDirection(walkDirection);
}