Captive Imagination
September 06, 2010, 09:56:58 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hosting change completed. Please send an e-mail to support@captiveimagination.com if you have any problems.
 
   Home   Help Search Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Global Time Keeping and Player Movement  (Read 412 times)
0 Members and 1 Guest are viewing this topic.
Eggsworth
Newbie
*
Offline Offline

Posts: 15


View Profile
« on: November 22, 2009, 02:15:38 AM »

The game I am currently working on involves guns as well as players moving around.
What is a way I can keep a global form of time keeping, so that even at different framerates, players will still move and shoot at the same "speed"?
Right now my brothers fast computer moves his player around twice as fast as my friend on his slow computer does, and my computer is somewhere in the middle. - (btw I am using StandardGame)

Also, I am confused about how to safely manage player movement in a game of 20 players.
How do I make a cheat-resistant way for players to move around?

Thanks!
« Last Edit: November 22, 2009, 02:30:06 AM by Eggsworth » Logged
Tumaini
JGN Developer
Jr. Member
*****
Offline Offline

Posts: 51


View Profile
« Reply #1 on: November 22, 2009, 03:33:11 AM »

You get a tpf (time per frame) value as argument to the game state update method.
If you use that to divide the movement into equal time steps it should make them move at the same speed.
How are you doing your update method?

As for cheat checking, you can either send only commands to the server (like move in this direction) and the server will calculate where you end up, but that is demanding on the server and is in many cases unnecessary.
Another way is to let the clients calculate your new position and send it to the server.
The server then checks if the new position in valid (depending on the old position, if the new position means you went through a wall and so on). If you're using sync you can do this in validateMessage in your GraphicalController.
Logged
Eggsworth
Newbie
*
Offline Offline

Posts: 15


View Profile
« Reply #2 on: November 22, 2009, 01:09:43 PM »

i see. i do not understand what you mean by how am I doing my update method?

my class is extending basicgamestatenode, and is running the update method as such. I have access to the tpf variable, so if i want movement speed to be "5" i just tell it to move the player at "5/tpf"?

Thanks for the information btw Smiley
Logged
Tumaini
JGN Developer
Jr. Member
*****
Offline Offline

Posts: 51


View Profile
« Reply #3 on: November 22, 2009, 03:05:59 PM »

I haven't used GameStateNode yet, but I assume you're assigning GameStates as children to your node?
The update method in the GameState that is responsible for moving your player forward should take into account the time per frame.

Well, if you want to move the player at 5 units per second you tell it to move 5*tpf units (you want to multiply the speed by the time per frame to get the change in position). E.g. player.getLocalTranslation().addLocal(getVelocity().mult(tpf));
Logged
Eggsworth
Newbie
*
Offline Offline

Posts: 15


View Profile
« Reply #4 on: November 22, 2009, 03:20:55 PM »

right now i move my player around with
Code:
movementSphere.addForce(new Vector3f( -12, 0, 0 ));

however, multiplying by the scalar tpf makes my movement very weak (not noticeable) and dividing causes an internal error! heh.

i am confused what tpf represents? (obviously time per frame) however, wouldnt it be better to multiply by desired framers per second/ actual frames per second? or something like that

therefore if you are getting the desired 60 frames per second, you move at 5 * 1 speed, however if you are only running at say, 15 frames per second, in that same second you move at 5*4 speed?

i am confused about this Tongue sorry!

edit: sorry, i was making a mistake. giving a float and multiplying it by tpf (i was using the wrong tpf variable! i needed the one out of my update method) and then applying it the node with force works appropriately. thanks for the help
« Last Edit: November 22, 2009, 07:26:00 PM by Eggsworth » Logged
Tumaini
JGN Developer
Jr. Member
*****
Offline Offline

Posts: 51


View Profile
« Reply #5 on: November 23, 2009, 05:04:04 AM »

I'm glad to see it worked out!
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.181 seconds with 21 queries.