Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/19/24 18:45
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, Ayumi, kzhao, 7th_zorro), 735 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
calculate time it will take to reach destination... #402845
06/10/12 21:57
06/10/12 21:57
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
I am creating a tile based game, but the world is too big to have everything loaded at the same time. So I only load what is surrounding the player and update the view as he moves. Even though the world is tile-based this is not a turn-based game, the movement of the player and enemies is real-time.

For this reason any enemy outside the inmediate view will have tile-based "timed" pathfinding, because there will be no phisical world/objects/enemies loaded outside of the current view they will just be data moving around in an array until they are in the player's current view.

When an enemy is inside the view the timing between each move is easy... Move towards the next tile in the "pathfinding-list" and when he has reached it go to next, etc...
The problem is with enemies outside of the view. Since they are not phisically moving they are only data being shifted in an array. Obviously the time needed to move the data in an array to the next tile is virtually zero, so I want a "wait(-x);" instruction between each move of the enemies that are outside of the player's view.

The problem is knowing the value of "x" in the wait instruction... Each enemy type has a different speed and I want it to be accurate even when not "phisically loaded" in the current view.

EXAMPLE:
for an enemy loaded (inside the view) this is quite simple, lets say he is in tile 3,3 and the next "path-node" is 3,2. The move would look somethng like this if each tile is of size 32*32:
Code:
destination.y=32*2;
character_speed=world[3][3].npc.speed;

//MOVE ENEMY IN THE REAL WORLD
while(my.y>destination.y)
{
   my.y-=character_speed*time_step;
   wait(1);
}
my.y=destination.y;

//UPDATE ENEMY POSITION IN THE ARRAY
world[3][2].npc=world[3][3].npc;
world[3][3].npc=NULL;

that move function will take whatever time it needs to reach the tile and then the next movement will be executed for the next tile in the path.

What I would like some help on is to pre-calculate the time it would take to move one tile withought actually phisically moving an entity. the function for moving like this on a grid would look something like this:
Code:
character_speed=world[3][3].npc.speed;
//ONLY MOVE ENEMY IN THE ARRAY BUT AT THE CORRECT SPEED
walk_delay=???;
wait(-walk_delay);
world[3][2].npc=world[3][3].npc;
world[3][3].npc=NULL;



Of course the real walk function is more complex, turning the npc to look towards the correct direction, animating, recieving coordinates as variables, etc... But for simplicity this is just a dumbed-down example with only the essentials. What I am having trouble with is figuring out how to calculate the "???" in the second example (virtual movement in the array with a delay depending on speed, not real-world phisical movement).




"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: calculate time it will take to reach destination... [Re: Carlos3DGS] #402846
06/10/12 22:20
06/10/12 22:20
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Actually, it is pretty simple, if you take a closer look at the equations and forget about wait(1) as tool for the timing.

The actor has a certain speed which you apply in the inside view each frame by adding/subtracting speed * time_step. Since a tick is a 1/16th of a second (16 ticks = 1 second), and time_step is just the inverse of the passed time since last frame in ticks, "speed" is actually the distance walked by the actor in 1/16th of a second, no matter what fps you have. E.g. if speed is = 5, the actor walks 5 * 16 = 80 quants in one second.

Now, consider the following: if the distance between the actor and the destination is distance = abs(my.y - destination.y), the actor has to walk "distance" quants to reach the next tile. If "speed" describes how much quants he walks in one tick, "distance" : "speed" equals the number of ticks the walk consumes; divided by 16 you have the number of seconds you have to wait. Here a bit code to demonstrate this:

Code:
var speed = 5; // walked quants per ticks
var distance = absv(my.y - destination.y); // walking distance in quants
var waitTicks = distance / speed; // ticks to wait for walk
var waitSecs = waitTicks / 16; // seconds to wait for walk



So, when and how do you trigger the tile change? Well, I would calculate 1) the walking time and 2) the walking destination in two fields per actor. Then, in a loop with wait(1) statement, I would iterate over all outside view actors and count the walking time down by time_step, thus the walking time field means actually the -remaining- walking time. If the walking time counter is 0 or less, the actor has reached the walking destination - in that case you do the change.

Last edited by HeelX; 06/10/12 22:22.
Re: calculate time it will take to reach destination... [Re: HeelX] #402847
06/10/12 22:47
06/10/12 22:47
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Thankyou very much!


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1