Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Kyo

Variable speed on a tile based map: How?

This topic is 5632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been having trouble with letting my character move smoothly across a tile based map, as the player must belong to a certain tile at any one time, so when he changes direction in between tiles it creates all sorts of problems during collision detection. I''ve tried several things like everytime before he stops or changes direction the program automatically places him in the centre by continually moving him and checking whether he''s in the center using mod(), but the result is a non-intuitive movement where he seems to jump tiles and jerk about.

Share this post


Link to post
Share on other sites
Advertisement
instead of making him move tile by tile, let him move wherever he wants. set an ''anchor'' point that you can use to snap through the tiles.
here''s a good analogy: if you''ve ever used a decent paint program, then you know what the "snap to grid" feature does. think of your character as the mouse cursor and the grid as your map. your mouse cursor moves smoothly over the grid surface, but the paint program only keeps track of which "grid space" you''re in.
you can do this with simple division..


-eldee
;another space monkey;
[ Forced Evolution Studios ]


::evolve::

Do NOT let Dr. Mario touch your genitals. He is not a real doctor!

Share this post


Link to post
Share on other sites
Hi, Kyo.

I don''t know if this would work, but you can try it:
Use two vector for storing the player''s movement; the current movement and the desired movement.
Your character will move using the current movement vector, and the player''s input will change the desired movement vector. Change the current movement vector to the values stored in the desired movement vector only when the character is centered over a tile. i.e.: if your character is moving right, but the player is pressing the down cursor, your character will keep moving to right until it reaches the center of the tile where it''s going to be.
To avoid the sensation of not having the inmediate control of the player, allow changing the current movement vector if the desired movement vector is the opposite. i.e.: if your character is moving right and the player press the left cursor, change the current movement vector even if the character is not centered over the tile.

I hope that works . Good luck!

theNestruo

Syntax error in 2410
Ok

Share this post


Link to post
Share on other sites
Eldea and theNestruo: That''s actually what I tried to do

Sounds right on paper but in practise when the player moves the "snapping to grid" just isn''t natural, for example you press right leave it and he snaps back to the other tile...

And as for changing direction only when he''s in the center of a tile you have to remember that it''s variable speed if you increment by +5 on a 32*32 tiles then no increment of 5 will centre directly on a tile.

I was wondering if anyone actually did this before, as there are plenty of problems when you actually try to implement it that you couldn''t have foreseen.

Share this post


Link to post
Share on other sites
have you tried putting movement commands in a FIFO que which you don't process until the last movement command has finished? If you have moved the distance per tile, then you check if there is another command to process.

EDIT:
with variable speed you just have to make sure that your next movement update will never take you past the center of the next tile unless the next movement command is in the same direction in which case you pop that command off the que as well.

[edited by - evillive2 on April 20, 2003 2:43:32 PM]

Share this post


Link to post
Share on other sites
what you are trying to implement, sounds just like the rules of movement for Diablo (have you played that game?) ... anyway, there is a grid based map, the same size as the characters, and when you begin moving in a given direction, the game will NOT interupt that movement, until you hit the center point of the next grid ... so like if you say, move 10 east .... but in the middle of the second movement you click north, then the game will finish the current movement (into the 2nd east square), and then begin moving you north ... and so the artist only have to come up with smooth animation transitions for changes along the 90 degree lines ... (or 45 degree if your game allows diagonal movement) ...and each time a character hits a center point during movement (reaches his current destination) he simply looks to see if more movement is pending, and if so, plays the transition and then animation sequences ... if not, he stops)

Share this post


Link to post
Share on other sites
quote:
Original post by Kyo
And as for changing direction only when he''s in the center of a tile you have to remember that it''s variable speed if you increment by +5 on a 32*32 tiles then no increment of 5 will centre directly on a tile.


That''s true. I remember I once had the same problem on a project that finally was abandoned, but I could solve it doing something similar to this:

  
// Assuming current movement is from left to right

// and the player wants to go fromt top to bottom

// The four next variables are the signs (-1, 0, 1)

// of the movement vector and the desired movement vector

DirX=1;
DirY=0;
DesiredDirX=0;
DesiredDirY=1;
// Pixels that left to move

PixelsLeft=CurrentSpeed;
While (PixelsLeft--) {
// If the player is centered, change the direction

if (IsCenteredOnTile (PlayerX, PlayerY)) {
MovX=DesX;
MovY=DesY;
}
// Move the player one pixel

PlayerX += MovX;
PlayerY += MovY;
}


theNestruo

Syntax error in 2410
Ok

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!