Cant seem to get CharacterControl working

Hi all,



I’m trying to use CharacterControl to enable physics for a bunch of zombies in my game, but whenever I enable physics (as opposed to just moving the geometries themselves) they start sliding off in the Y-axis for a reason I don’t understand. My gravity is set in the z-direction and I’m not applying any other forces/ or using setWalkDirection() on them as of now.



Heres my code for the zombie:



[java]

public class Zombie extends Mob {

public Zombie(Game game){

this.game = game;



pos = new Vector3f(0,0,1);

rot = new Quaternion();



Box b = new Box(new Vector3f(0,0,0), 0.5f, 0.5f, 1f);

geom = new Geometry(“Zombie”, b);

Material mat = new Material(game.getAssetManager(), “Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.Black);

geom.setMaterial(mat);

game.mobs.attachChild(geom);



physChar = new CharacterControl(new CapsuleCollisionShape(.5f, 1f, 1), 0.01f);

geom.addControl(physChar);

game.bulletAppState.getPhysicsSpace().add(physChar);



geom.lookAt(game.player.getWorldPos(), Vector3f.UNIT_Z);



update();

}



@Override

public void update(float tpf){

if(!isDead()){

Vector3f target = game.player.getPos();



pos = physChar.getPhysicsLocation();



Quaternion old = new Quaternion(geom.getLocalRotation());

geom.lookAt(target, Vector3f.UNIT_Z);

geom.getLocalRotation().slerp(old, turnSpeed); // the higher the value, the slower rotation



//geom.setLocalTranslation(pos);

//physChar.setWalkDirection(target);

rot = geom.getLocalRotation();

}

}

}

[/java]



I stripped out some code that doesn’t deal with physics just for simplicity.

My entire game is located here: https://github.com/ildrean/TerraNullius



Any help would be greatly appreciated; this problem has been vexing me for a while.

Y is up, X is right, Z is towards you

which meant my friend that Vector3f.UNIT_Y is all what you want

I actually have my camera flipped so that x and y are in the plane and z is up and down, its probably a bad practice though, heh.



I tried changing the direction of gravity with

[java]bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0f,0f,-1f));[/java]

but the direction doesn’t seem to matter, the zombies always slide off to the right regardless - even if I set it to 0,0,0.



As far as I can tell there is nothing being called to move them in their update loop (since I commented it out to test this) and this only started happening when I made them physics enabled.

Y is up! The character has its own physics simulation, setting the global gravity will not influence it

Ah, I didn’t realize that the character wasn’t affected by global gravity. I’ll try that, sounds like its the issue.



Is there any reason to use y as up other than because that is the default or accepted practice? I only ended up using z as up because the quad I was using for the floor draws that way by default, and z is generally up coming from a math or physics perspective.



Edit: I decided to bite the bullet and flip my coordinate space so Y is up, works better now, though seems backwards to me a bit.

In OpenGL what I said is the default. You could go on and redefine everything but as always, it only makes your life harder. Theres nothing “backwards” about it, its just different names. For coordinate systems your question should always be “left or right handed?”