Camera

when i walk forward it is ok

but when i walk backwards left/right it flicks

http://www.screenr.com/Jzk8



andy help appreciated

You are rotating too far. Check and make sure you are rotating in radians and not degrees. This says how to convert.

Also the examples that come with jme should work out of the box. If you have changed code and not posted nor mentioned that then we cannot help you.

@Sploreg said:
You are rotating too far. Check and make sure you are rotating in radians and not degrees. This says how to convert.
Also the examples that come with jme should work out of the box. If you have changed code and not posted nor mentioned that then we cannot help you.



[java]
@Override
public void simpleUpdate(float tpf) {
Vector3f camDir = cam.getDirection().clone().multLocal(0.1f);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.1f);
camDir.y = 0;
camLeft.y = 0;
walkDirection.set(0, 0, 0);
if (left) {
walkDirection.addLocal(camLeft);
System.out.println("sdfsdf");
}
if (right) {
walkDirection.addLocal(camLeft.negate());
}
if (up) {
walkDirection.addLocal(camDir);
}
if (down) {
walkDirection.addLocal(camDir.negate());
}
if (!character.onGround()) {
airTime = airTime + tpf;
} else {
airTime = 0;
}
if (walkDirection.length() == 0) {
if (!"stand".equals(animationChannel.getAnimationName())) {
animationChannel.setAnim("stand", 1f);
}
} else {
character.setViewDirection(walkDirection);
if (airTime > .3f) {
if (!"stand".equals(animationChannel.getAnimationName())) {
animationChannel.setAnim("stand");
}
} else if (!"Walk".equals(animationChannel.getAnimationName())) {
animationChannel.setAnim("Walk", 0.7f);
}
}
character.setWalkDirection(walkDirection);
}
[/java]

The way that’s written, when going backwards walkDirection will flip back and forth since it’s setup to turn the character around when moving backwards… so then the next backwards flips it around again.

1 Like
@pspeed said:
The way that's written, when going backwards walkDirection will flip back and forth since it's setup to turn the character around when moving backwards... so then the next backwards flips it around again.

oh ok i understand, so how would i fix this?

bump

Step 1: decide how you want it to work, ie: should “back” turn the character around or make it walk backwards?

@pspeed said:
Step 1: decide how you want it to work, ie: should "back" turn the character around or make it walk backwards?

"back" should just move character position backwards, no rotating

Then don’t change the camera direction:

character.setViewDirection(walkDirection);



Don’t set the camera view direction to the walk direction if you don’t want the view direction to be the walk direction.

@scarecr0w said:
bump

do. not. bump. threads.

Questions will be answered when the people wake up from their various timezones and get off work.
1 Like
@pspeed said:
Then don't change the camera direction:
character.setViewDirection(walkDirection);

Don't set the camera view direction to the walk direction if you don't want the view direction to be the walk direction.

thankyou, but now i lose the walking towards the direction my mouse is pointing, like its strictly only w for forward, not w for forward + mouse pos
@scarecr0w said:
thankyou, but now i lose the walking towards the direction my mouse is pointing, like its strictly only w for forward, not w for forward + mouse pos


Nothing in the code you posted has anything to do with mouse direction. It sets the walk direction purely on what keys are pressed... and then sets that as the look direction. So it's no surprise that you end up looking where the keys say to walk.

If you have other code that does things based on the mouse then you will have to post that also... but that is unrelated to the setViewDirection() I told you to remove.

Or maybe you mean that you want to set view direction to the direction that the camera is facing. In that case, set view direction to camera direction... not walk direction.
1 Like
@pspeed said:
Nothing in the code you posted has anything to do with mouse direction. It sets the walk direction purely on what keys are pressed... and then sets that as the look direction. So it's no surprise that you end up looking where the keys say to walk.

If you have other code that does things based on the mouse then you will have to post that also... but that is unrelated to the setViewDirection() I told you to remove.

Or maybe you mean that you want to set view direction to the direction that the camera is facing. In that case, set view direction to camera direction... not walk direction.


thanks it works now appreciate it.