Giving characters life! (moving them around)

Heyylllooo everybody!



I am making an MMORPG, and in doing this I obviously need a character, and I'd like him/her/it to move.



One important fact about my mmorpg is that it will contain actual gravity (using jME physics 2, of course) to allow characters to jump and fly (with flying mounts, of course). So, in making this character move, should I apply a forwards force to the character, and have the animation play during the running, or should I just use "setLocalTranslation" and increment their position, while simultaneously playing the animation?

As far as I know, for models controlled by physics it is best to interact with the physics engine instead of with jME. So you should use forces, velocities etc to move characters around

What else are you using physics for? Impassable obstacles? Explosions which affect other objects? Bouncing? Falling over? Pushing objects?



If you avoid physics, there are various tests (like TestThirdPersonController) where you move in x and y and set the localtransform based on the height of the height map at a point… You can add to this height offset (or limit Y axis based on height map) to make your character appear to jump or fly.



For physics, heres a great tutorial for walking/turning/jumping movement:

http://wiki.jmephysics.irrisor.net/tiki-index.php?page=Tutorials



Moving with physics is hard, since if the size of your game object differs, you need to configure it to use the correct forces and torques.

Flying is also more difficult to jumping. Are you gliding? Floating? Hovering? Using a jetpack with burst motion? What happens when you stop? Do you float downwards?
Momoko_Fan said:

As far as I know, for models controlled by physics it is best to interact with the physics engine instead of with jME. So you should use forces, velocities etc to move characters around


But should I do it by physics or just increment their position? If I didn't do it by physics I don't need the physics engine, and I could just increment their position and have them play their animation.

If you only need a crappy gravity effect, you could implement it yourself, and do everything without the need of a physics engine. With this, you would be able to actually use simple translations, rotations instead of forces and torques.

I want World of Warcraft type flying. You press space bar to go up, you always go up at an even rate, and when you stop rising you stay suspended–you don't fall to the ground or have to glide forward.



I want characters to be able to run, jump, walk, and swim.



Seems like just changing the characters' local translation and applying an animation while doing it is much simpler?

Thats what I do for DarkMMO. 



Im not trying to do flying… that adds a whiole lot of issues I dont want to deal with right now.  I have a velocity in x and y that I multiply by the update delta and add to x and y of the object.  When the animation stops I set them to 0.  I set Z based on the z of the walk mesh at the current x and y point.

jeffpk said:

Thats what I do for DarkMMO. 

Im not trying to do flying... that adds a whiole lot of issues I dont want to deal with right now.  I have a velocity in x and y that I multiply by the update delta and add to x and y of the object.  When the animation stops I set them to 0.  I set Z based on the z of the walk mesh at the current x and y point.


By "Thats what I do..." I assume you mean just changing the local translation without using the physics engine. Why would flying add more issues? It seems to me it would be quite easy to do--just manipulate the Y value along with the X and Z values, and you have flying. I'd like to add a barrier (probably just a final integer) that would prevent the Z translation from going too high, because you know the first idiot who gets a flying mount is going to be like "MAN I WONDER HOW HIGH I CAN FLY BEFORE I CRASH THE SERVER HAHAHAHAHA."

Anyway, if you're not using physics, what is this "velocity" you describe? And the "update delta" I assume is the last position of the character and the position of the character now... I had assumed it would just look something like this...


Vector3f myLocation = character.getLocalTranslation();
int x, y, z;
x = myLocation.getX();
y = myLocation.getY();
z = myLocation.getZ();

if(//moving forward)
z -= MOVE_RATE;
if(//moving backward)
z += MOVE_RATE;
if(//moving left)
x -= MOVE_RATE;
if(//moving right)
x += MOVE_RATE;
if(//moving upward)
y += MOVE_RATE;
if(//moving downward)
y -= MOVE_RATE;

Vector3f myTargetLocation = new Vector3f(x, y, z);
character.setLocalTranslation(myTargetLocation);



Wouldn't that work?

Obviously the ground would have to be a boundry.

You multiply velocity (speed and direction in a vector) to figure out how far you have gone in the time given to you in the update method (update delta) to get the distance travelled.



Adding a set distance to each coordinate will work (mostly… strafe and forwards together will be faster than strafe or forwards…), but where are you putting this code? If it is in the update method you don't know how many times it will be called a second. You may get speed based on fps… Which is bad for mmos…

How do I get the direction of a Vector. Since Vector3f is really just a 3-dimensional point, I don't understand how it has a direction? And is update delta just available to me in the update method? Is it some hidden variable in StandardGame, or is it something I'll have to do myself?

you can get the direction of a quaternion as a Vector3f:

-> Vector3f direction = node.getLocalRotation().getRotationColumn(2);



the update delta is the 'time per frame'.

In StandardGame this time is passed into the update(float tpf) method.

In SimpleGame you have to use the timer to get the tpf:

-> Timer.getTimer().gettimePerFrame();



to move a character independent of the Frame rate you multiply the characters speed with the tpf.

character.getLocalTranslation().addLocal(direction.mult(tpf*speed));

A vector can be a specific point in space or a direction, (0,1,0) is a vector that is pointing straight up.  2 vectors can give you a specific point in space and a direction in relation to that point.

Here’s a nice vector math tutorial: http://chortle.ccsu.edu/VectorLessons/vectorIndex.html

I understand vector math quite well, actually. I just haven't gotten used to it in video-games. To me, vectors were always rays formed by two points or an angle. I understand scalar multiplication and dot product and all of that goodness.


Core-Dump said:

you can get the direction of a quaternion as a Vector3f:
-> Vector3f direction = node.getLocalRotation().getRotationColumn(2);

the update delta is the 'time per frame'.
In StandardGame this time is passed into the update(float tpf) method.
In SimpleGame you have to use the timer to get the tpf:
-> Timer.getTimer().gettimePerFrame();

to move a character independent of the Frame rate you multiply the characters speed with the tpf.
character.getLocalTranslation().addLocal(direction.mult(tpf*speed));


I was hoping to use ThirdPersonController, does this change anything?

well the ThirdPersonController does this stuff for you, except flying :slight_smile:

Trussell said:

jeffpk said:

Thats what I do for DarkMMO. 

Im not trying to do flying... that adds a whiole lot of issues I dont want to deal with right now.  I have a velocity in x and y that I multiply by the update delta and add to x and y of the object.  When the animation stops I set them to 0.  I set Z based on the z of the walk mesh at the current x and y point.


By "Thats what I do..." I assume you mean just changing the local translation without using the physics engine. Why would flying add more issues?


Doing 2.5D motion, I can (and do) use a walk mesh to determine collision with walls and such.

If you allow full 3D motion you have to do collision v. the actual geometry of the world, which is half way to a true physics model.
Core-Dump said:

well the ThirdPersonController does this stuff for you, except flying :)


So what do I have to modify to implement flying?:

Well, as jeffpk was eluding to this would be true 3D motion; you will have to handle collisions with a 3D approach rather than a 2D approach (like using a tile mesh with some walkable).

Trussell said:

Core-Dump said:

well the ThirdPersonController does this stuff for you, except flying :)

So what do I have to modify to implement flying?:


i would just alter localTranslation().y when you press the specific button.
But its very game specific how you want to implement it.
Core-Dump said:

Trussell said:

Core-Dump said:

well the ThirdPersonController does this stuff for you, except flying :)

So what do I have to modify to implement flying?:


i would just alter localTranslation().y when you press the specific button.
But its very game specific how you want to implement it.


If I use an OBJ file as my terrain, can't I just set that model to be impassible so the character won't fall through the world?