# Moving objects - setting different speed

• 08-10-2009, 05:19 AM
Antigol
Moving objects - setting different speed
Hi, sorry my english.

I'm making a football game in Java. I tried to make it in other languages in the past (delphi and vb6) and in all of them I had the same question which I can't even now solve.

It might be a conceptual one, that's why Im asking here.

I have a class player which calculates where a player should move (an X and Y point) and then through some math calculations I get whether he should move 1 or 0 of X and 1 or 0 of Y to reach that point.

So if my player is on X:200,Y:200 and he has to move to X:400,Y:400, he will move 1 of X and 1 of Y each time my timer is fired until he reaches point 400,400.

To show the player's movement to the user, I have a timer which is launched each 1 ms (it fires an event who moves the player by repainting) and it works fine (I can see my players moving through the screen). But the problem is that even using 1ms my players only move in a normal speed. I can't make my fastest player to move more quickly. I can do this only by moving him 2 by 2 instead 1 by 1 but when you see the player's movement you can see the "jumps" he does.

How can i simulate different speed in player's movement?

• 08-13-2009, 05:57 AM
Singing Boyo
The only way is to slow down how quickly the 'normal' speed timer fires.

e.g

Very Fast: 1 ms
Fast: 2 ms
Normal: 3 ms
Slow: 4 ms
Very Slow: 5 ms

This will simulate different movement speeds for the players.
• 08-14-2009, 01:14 AM
Mr.Beans
What I would do is map the world to a floating point coordinates system (or some sort of adjusted size coordinate system), and just fire the timer off more often. I'm guessing that the x,y that you are using are actual pixels on the window. That makes it so that if someone is going 1 pixel per second, the next fastest person has to be going twice as fast.

Someone going 1.25 and someone going 1.50 would be much more realistic.

Mr. Beans