Question over Walking Character and "walking" speed

Hello all, I have a question over the Walking Character exemple.

It’s about the walking speed, this part of the code:

Vector3f camDir = cam.getDirection().clone().multLocal(0.25f);



I want to know, if I had 200 FPS the player will be more faster than a player with 30 FPS ?



PS: Sorry for my bad english :confused:

Not just he, But the entire app will xD.

i also wondered about this a few days ago :P, but incorporating tpf into it, screws it up, so I think the charactercontrol handles this difference for you. So the answer to your question is no, they should both move the same :slight_smile: (i think). You can check this by setting vsync, and see if it makes a difference

Ok but he will walk more faster ? So I need to do it for “correct” the speed:



float time = System.currentTimeMillis()-lastUpdate;

Vector3f camDir = cam.getDirection().clone().multLocal(0.025f*time);



?

Why are you worrying about it? The app handles it for you.

Because it’s for predicting the client movement in an online game…

When you talk about FPS are you talking about the jME application’s fps (e.g.: SimpleApplication.update(float fps))? This is the global fps. It will update your app as a whole. There’s no sense.

I just want to know if somebody with a more powerful computer will walk more faster than somebody with a minder powerful computer…

As I said “Not just he, But the entire app will!!!”.

Ok, thank you

Read the manual, you should use the tpf value to check time passed, not currentTimeMillis

I know it s a old topic but did you know using the tpf in the jmonkey 3.1 alpha give hit to the camera (it s like teleportation…)

pretty annoying.

I was wondering if I did something wrong with the code so I will post it right here.

public void update(Main app, float tpf) {
        walkDirection.set(0f, 0f, 0f);
        
        if(run){
            WALKSPEED = 5f;
        } else {
            WALKSPEED = 1f;
        }
        if (left) {
            walkDirection.addLocal(WALKSPEED, 0, 0);
        }
        if (right) {
            walkDirection.addLocal(-WALKSPEED, 0, 0);
        }
        if (up) {
            walkDirection.addLocal(0, 0, WALKSPEED);
        }
        if (down) {
            walkDirection.addLocal(0, 0, -WALKSPEED);
        }
        
        if(walkDirection.getX() != 0 && walkDirection.getZ() != 0){
            walkDirection.setX(walkDirection.getX()/2);
            walkDirection.setZ(walkDirection.getZ()/2);
        }
        RotatePlayer rot = new RotatePlayer();
        character.setViewDirection(rot.rotatePlayer(character.getPhysicsLocation(), app));
        character.setWalkDirection(walkDirection.mult(50).multLocal(tpf));
        
        app.getCamera().setLocation(character.getPhysicsLocation().add(0, 100, -100)); 
    }

I think walk direction shouldn’t be multiplied by tpf. I could be wrong but I thought it was really walk velocity and tpf is taken into account internally.

That’s true. Walkdirection.length() is the Meter per second and that will be the speed of the character.

The fault is the getCamera.setlocation, I do it the same and have jitering at high speeds, this seems to be because it’s not in sync and/or not damped (like you should smoothen it somehow).

This should be another topic though and not a reply to an old one

The issue of “jittering” is update order.

1 Like

Yep, can’t set the camera location until much later… after all of the controls have been run. For example, move that to render() instead.

1 Like

Or just another control after the physics control :slight_smile:

1 Like

Yea but with out the multi(tpf);
it s fine but the speed would depend on the fps :s

I will give a try and set the camera in the render, i will post later if it did solve the problem!

No. That is incorrect because it is velocity so the time is already calculated into the speed on the physics side. In fact, the way you have it means that it will be frame rate dependent with the multiply.

Unless I’ve totally misunderstood the setWalkDirection() and it’s even more improperly named than I thought. (For example, it seems to really be walk velocity and not direction.)

So I never have to use the tpf, and everyone would still be walking at the same speed no matter what is the fps on there screen?

Sorry for all those question, but i must be certain if I plan to make a online game.
Otherwise the server would always rollback the position of the player and it would be anoying.