Physics Walking Character Question

In TestWalkingChar.java and Golem.java their are 3 method calls at the bottom of the updateMethod that doesn’t seem to do anything. The static Quanternion ROTATE_LEFT and the Vector3d modelRight doesn’t seem to do anything at all. I decided to randomly compare my implementation with these two classes and this seems to be the only thing missing. Can I ask What the purpose of these calls are and if adding them will avoid a problem in the future?





[java]

modelRotation.multLocal(modelDirection);

modelRight.set(modelDirection);

ROTATE_LEFT.multLocal(modelRight);

[/java]

You are wrong, read the javadoc. Quaternion.multLocal(Vector3f) stores the result in the vector.

I meant it did nothing visually as everything appears to work fine without it, however; it was obviously added for a reason so my implementation must be wrong without it, i’ll look into more.

Its used for placement of the bullet

ahh thnx for clearing that up i saw in the code where it connected

Im working on my own version of this class too for learning and I’m stumped as to why It wont do what I want it to do.



When I walk backwards, I always end up jumping backwards when that is not what I want (only want to walk backwards). My other problem is I cant get the cube to rotate to face where I am walking. SetLocalTranslation was doing nothing to the geometry so i tried rotating the physics object, which sorta works when I am walking but it doesn’t stay facing that direction once I stop (it reverts back to the original rotation). When it is rotated this way, it is always tilted in the direction the camera is tilted, which I do not want but am not sure how to stop (this would prolly fix my auto backwards jump problem too).



[java] public void simpleInitApp() {

BulletAppState bulletAppState = new BulletAppState();

stateManager.attach(bulletAppState);



//flyCam.setMoveSpeed(3);

flyCam.setEnabled(false);

initKeys();



//cam.setLocation(new Vector3f(0, 6f, 6f));

//cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));



//create landscape

Box b = new Box(Vector3f.ZERO, 20, 2, 20);

Geometry landscape = new Geometry(“Box”, b);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat.setColor(“m_Color”, ColorRGBA.Blue);

landscape.setMaterial(mat);



CollisionShape landscapeShape =

new CollisionShapeFactory().createSingleMeshShape(landscape);

RigidBodyControl landscape_psy = new RigidBodyControl(landscapeShape, 0f);

landscape.addControl(landscape_psy);

rootNode.attachChild(landscape);

bulletAppState.getPhysicsSpace().add(landscape_psy);



//create player

Box b1 = new Box(Vector3f.ZERO, 1, 1, 1);

player = new Geometry(“Box”, b1);

Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat1.setColor(“m_Color”, ColorRGBA.Red);

player.setMaterial(mat1);



CollisionShape playerShape =

new CollisionShapeFactory().createSingleDynamicMeshShape(player);

player_psy = new CharacterControl(playerShape,.05f);

player.addControl(player_psy);

rootNode.attachChild(player);

bulletAppState.getPhysicsSpace().add(player);



//move objects to starting location

landscape_psy.setPhysicsLocation(new Vector3f(0,-1,0));

player_psy.setPhysicsLocation(new Vector3f(0,50,0));



ChaseCamera camera = new ChaseCamera(cam, player,inputManager);

}



@Override

public void simpleUpdate(float tpf) {

Vector3f modelDirection = new Vector3f(0,0,2);

Vector3f walkDirection = new Vector3f(0,0,0);

Vector3f cameraDirection = cam.getDirection().clone().multLocal(.2f);

Vector3f cameraLeft = cam.getLeft().clone().multLocal(.2f);

Quaternion modelRotation = new Quaternion();

Matrix3f mat;

if(forward){

walkDirection.addLocal(cameraDirection);

}

if(backward){

walkDirection.addLocal(cameraDirection.negate());

}

if(left){

walkDirection.addLocal(cameraLeft);

}

if(right){

walkDirection.addLocal(cameraLeft.negate());

}

if(turnLeft){



}

if(turnRight){



}

modelRotation.lookAt(walkDirection,Vector3f.UNIT_Y);

mat = modelRotation.toRotationMatrix();

//player.setLocalRotation(modelRotation);

player_psy.setPhysicsRotation(mat);

player_psy.setWalkDirection(walkDirection);

}[/java]

Eliminate the y component of the direction vector you get from the camera.