Hi,
I’ve been trying for a while now to get an object (say the teapot) to move forward, back, turn left, turn right (no strafing!)and be able to get a camera look around + Collision (which is where I have the problem).
So I went to the teapot ChaseCam exemple and did this to the onAnalog:
[java] public void onAnalog(String name, float value, float tpf) {
if (name.equals(“moveForward”)) {
teaGeom.move(teaGeom.getLocalRotation().getRotationColumn(0).mult(5ftpf)); //old teaGeom.move(0, 0, -5 * tpf);
}
if (name.equals(“moveBackward”)) {
teaGeom.move(teaGeom.getLocalRotation().getRotationColumn(0).mult(-5ftpf)); // old teaGeom.move(0, 0, 5 * tpf);
}
if (name.equals(“moveRight”)) {
teaGeom.rotate(0, -5 * tpf, 0); //old eaGeom.move(5 * tpf, 0, 0);
}
if (name.equals(“moveLeft”)) {
teaGeom.rotate(0, 5 * tpf, 0); // old teaGeom.move(-5 * tpf, 0, 0);
}
}
[/java]
This is working great, whenever the object rotate, pressing up means forwards is wherever the object is pointing to but now how can apply that to a CharacterControl ? I can’t rotate the model (teaGeom.rotate doesn’t do anything here) or the CharacterControl (that I know of), I am using this but can’t do model.rotate (nothing happens), all I can do is move correctly
[java]…
CapsuleCollisionShape capsule = new CapsuleCollisionShape(1f, 1.2f, 1);
character = new CharacterControl(capsule, 0.1f);
teaGeom = assetManager.loadModel(“Models/Teapot.obj”);
teaGeom.addControl(character);
character.setPhysicsLocation(new Vector3f(0, 0, 0));
rootNode.attachChild(teaGeom);
getPhysicsSpace().add(character);
…[/java]
[java]
public void simpleUpdate(float tpf) {
Vector3f camDir = cam.getDirection().clone().multLocal(0.08f);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.08f);
//character
camDir.y = 0;
camLeft.y = 0;
walkDirection.set(0, 0, 0);
if (left) {
walkDirection.addLocal(camLeft);
}
if (right) {
walkDirection.addLocal(camLeft.negate());
}
if (up) {
//walkDirection.addLocal(camDir);
walkDirection.addLocal(teaGeom.getLocalRotation().getRotationColumn(0).mult(5ftpf));
}
if (down) {
// walkDirection.addLocal(camDir.negate());
walkDirection.addLocal(teaGeom.getLocalRotation().getRotationColumn(0).mult(-5ftpf));
}
character.setWalkDirection(walkDirection);
}
[/java]
Any idea pls (I don’t have any animation on the teaGeom, just a simple mesh that slides around, jumps and hit walls. How do I make it (teaGeom or CharacterControl) rotate so that I can then use that rotation to direct the forward and backward movement (basically I don’t want strafe but left and right (without use of the mouse for it other than to look around (it’s for android)).
PS: I also tried to play with setViewDirection where I could character.setViewDirection(walkDirection); but when I let go then walkDirection is reset and the teapot goes back to the 0,0,0.
Thank you in advance
so I found out I took something off the original example code that was useful if I want to use setViewDirection to point my mesh in the right direction, so here is the working code.
HOWEVER, I still don’t like the way it turns, straight, Straight/Turn or Turn… only 3 angles, not exactly a smooth transition.
how can I simulate mouse rotation ?
[java] public void simpleUpdate(float tpf) {
Vector3f camDir = cam.getDirection().clone().multLocal(0.08f);
Vector3f camcol = cam.getRotation().getRotationColumn(0).mult(1);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.08f);
//character
camDir.y = 0;
camLeft.y = 0;
walkDirection.set(0, 0, 0);
if (left) {
walkDirection.addLocal(camLeft);
didWeMove = true;
}
if (right) {
walkDirection.addLocal(camLeft.negate());
}
if (up) {
walkDirection.addLocal(camDir);
//walkDirection.addLocal(model.getLocalRotation().getRotationColumn(0).mult(5ftpf));
}
if (down) {
walkDirection.addLocal(camDir.negate());
//walkDirection.addLocal(model.getLocalRotation().getRotationColumn(0).mult(-5ftpf));
}
character.setWalkDirection(walkDirection);
if (walkDirection.length() != 0) character.setViewDirection(walkDirection);
}[/java]
I would still prefer the actual rotation if that’s possible since it’s smoother and that doesn’t mean having to setViewDirection at every update!
Coersum, I am struggling with a similar issue. The best answer I have found so far is in this page https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:walking_character?s[]=collision
where they use the way the camera is looking to adjust the walk direction. I will post an example If I get something working enough for me to like it.
As far as I can find though, there is no easy way to do rotation as with objects without physics.