Tile Based Movement

Posted By: Rasch

Tile Based Movement - 08/18/09 01:08

Hi there,

i´m currently thinking about how to realize a tile based movement system.

The best example for my needs is the game Ragnarok Online.

here´s a small example. You see the green box on ground.

Watch here!

I got all that stuff with tracing to ground and character walks to the location from my isometric view. But how to realize those tileset walking?

greets Rasch

edit:

One more thing is. I´ll use a 3d landscape and characters. not 2d laugh
Posted By: EvilSOB

Re: Tile Based Movement - 08/18/09 01:26

Depends on how your "character walks to the location", but the basic concept looks to be this.

When the user clicks a location to walk to, set the target location
to be the-center-of-clicked-tile rather than the actual click location.

Also, when the character begins walking, calculate his from tile-center to tile-center.
That is...
<1> Calculate angle from 'here' to 'destination'.
<2> Round off angle to nearest 45 degrees. (0,45,90,135,etc)
<3> "smoothed" rotate player to face new angle.
<4> Once <3> is complete, walk forward to center of tile being faced.
<5> Once <4> is complete, stop moving.
<6> If 'destination' not yet reached, then loop back to step <1>.
<6A> Round off angle to nearest 90 degrees. (0,90,180,270)
<6B> "smoothed" rotate player to face new angle.
Posted By: Rasch

Re: Tile Based Movement - 08/18/09 01:40

Ok that is some good point for a start but first of i wanted to bring the mouse cursor moving in a tile based movement. Means not smoothly everywhere but in steps.

Thanks for the help laugh
Posted By: EvilSOB

Re: Tile Based Movement - 08/18/09 01:53

Im not sure what you mean by that.
If you mean moving toward the mouse, while a mouse-button is held,
then just recalculate the 'destination' EVERY step <1>, and change step <6> to
<6> If 'destination' not yet reached, or mouse-button still pressed, then loop back to step <1>.

Or are you talking about moving the mouse-pointer ITSELF in steps?
(cause the video doesnt look like that to me)
Posted By: Rasch

Re: Tile Based Movement - 08/18/09 02:15

Yes thats what i mean. The mouse pointer in those tiled steps. Ragnarok also use this method. the mouse pointer shows the tiles on the floor and jumps from tile to tile while movig mouse.

greets
Posted By: EvilSOB

Re: Tile Based Movement - 08/18/09 02:44

Hmmm, I can "kind of" see it.

OK, my best idea would be this.

Create a new mouse-pointer as a "view-entity". (Check manual if required)

Write a function that will stay running.
This function will monitor the REAL mouse position (using mouse_pos or mouse_cursor),
and will smooth-move the view-entity pointer toward the center of the tile that the REAL mouse is over.

When movement testing is complete, set "mouse_pointer=0;" in main to hide the 'normal' arrow.
Posted By: Rasch

Re: Tile Based Movement - 08/18/09 09:02

ok you´r talking about taking the center of the tile. But i´ve got no tiles in my game. I trace from camera trough mouse to ground and set the target location where left clicked.

Now my thoughts were that i create small tiles and place them on the ground and the trace looks for those tiles and finds the center of them but this would mean that i have to use a lot of entitys.

So what do you exactly mean by your tiles?
Posted By: EvilSOB

Re: Tile Based Movement - 08/19/09 00:49

You're asking me?
You want tile-based movement, but you've got no tile?
C'mon man, keep it real.... grin

Serious now.
I assumed your 'ground' was going to me made up of tiles,
and I think that was a sensible assumption on my part.
But if there is no 'actual' tiles, then we 'fake' them instead,
no need to create invisible tiles.

My sense of scale may be wrong here, it depends on your terrain sizes
and model sizes, so bear with me. Im basing this on the visual look of the video.

Lets say your player is 20 quants tall. The tiles look to be about half that.
SO player = 20 quants tall, tiles = 10 quants long/wide.
So to achieve our tile-like movements, we will make our fake tile positions
to be the 'corner' of each tile. (This simplifies the later calculations)

So from now on, whenever we have a target XY position of any sort, be it
a destination, a portal point, a dropped object, or whatever,
we need to "round-off" is position to that of a tile-corner.
In this example, to the nearest multiple of 10.

So lets say the mouse clicks at XY position 123,47
Your target position wants to be "rounded off" like so,
target.x = integer(target.x/10+0.5)*10;
target.y = integer(target.y/10+0.5)*10;
So our target position is now 120,50.

See how this is "faking" a tile position?
So if every position in the game is 'rounded' like this
then it will appear tile-like.
Posted By: Rasch

Re: Tile Based Movement - 08/20/09 10:38

Ok seems like that it works. But the tile steps are very small. I tried everything this but can´t get it to work.


edit: ok my fault i got it to work. Thanks a lot laugh
© 2023 lite-C Forums