2
\$\begingroup\$

Sorry if my title is a little vague, I wasn't entirely certain how to word this specific question.

I'm developing a small little MMORTS game, and in this game is the world map which consists of thousands of tiles (the view on the client is an isometric grid). The world map data is stored in a MySQL database table. This table stores each individual tile and the tile data. So when the player visits the world map screen, the server will load a chunk (12x12) of the world map at a time for the client to render.

Now, it's come to the point where I need to allow players to send planes from their cities that are on the world map, to other tiles around the world map. For instance, a player that owns City 1, which is located on tile 100,100, wants to send a plane to an oil well on tile 60,60.

How can I show the movement of that plane from the city -> destination in real time across all clients in the most efficient manner? Let's assume each game server can have hundreds of players, so we can expect thousands of flights across the world map at a time.

When a flight is created, it would be stored in the database with data such as destination_x, destination_y, origin_x, origin_y, flight_speed.

And when a client loads a chunk of the world map at whatever coordinates, I can query the database on each chunk load to see if any flights are currently crossing this chunk. However, how can I do this? With the data I just mentioned that would be stored for a flight, how could I determine if a flight is currently in a given chunk? Let's assume a chunk is 12x12 tiles.

How should I go about doing this, and is my current thought-out method the most efficient approach to this problem?

~~~~~~~~~~~~

If context helps, here is a picture of the world map:

enter image description here

I would like for flights to show up across this world map as they are heading to a destination from a given origin. The plane should only load if it's crossing this viewed chunk by the client.

~~~~~~~~~~~

I apologize if this question is still too vague, I tried my best to explain my current situation and problem. If you have any questions, please ask. Thanks!

\$\endgroup\$
2
  • \$\begingroup\$ If it's real time you should be measuring out time. You need total flight time and elapsed flight time. Also, can the plane go over your obstacles? Lastly, does your plane need to be in a given tile at every moment? I would calculate the path (ie: the tiles needed to get to the next city) and then take the TotalFlightTime / numTiles = incrementTime and then using an elapsedTime if(elapsedTime > incrementTime) { advanced one tile. Reset elapsedTime } \$\endgroup\$ Aug 5 '15 at 11:15
  • \$\begingroup\$ Context: Josh's earlier question about calculating the position of such a flight at time t. \$\endgroup\$
    – Anko
    Sep 4 '15 at 13:43
1
\$\begingroup\$

This should be similar to all movement in that it can be described by location, a point, and velocity, a vector. It is reasonable to assume that the flight takes a predetermined amount of time in seconds or ticks. You can calculate the velocity based on the distance and time of flight. Unfortunately this exchange does not have latex implemented so this might look a bit rough.

Plane is to travel a distance d in a given number of seconds t from point p1 to point p2 where d = \sqrt( (p2_x - p1_x)^2 + (p2_y - p1_y)^2 ).

Let us define the number of seconds per tick as q, then the number of ticks required for the flight is c = t/q.

Now we need to determine the velocity vector v, we want the slope from p1 to p2, and the magnitude from distance divided by the flight time.

First we create a unit vector pointing from p1 to p2. u = \frac{1}{d} (p2 - p1)

Then we scale the unit vector by d/c. v = \frac{d}{c} u

The planes position at any given tick (during the flight) is p = p1 + number_of_ticks_in_air * v

\$\endgroup\$
0
\$\begingroup\$

Using these variables

float elapsedTime
float totalFlightTime
float incrementTime
int numTiles

ElapsedTime is the current position in time and should be advanced with delta time every frame.

TotalFlightTime is the total amount of time the flight should take.

NumTiles is the total number of tiles needed to advanced to the next city.

Now set incrementTime = totalFlightTime / numTiles to get equal parts of totalFlightTime.

Then use

if(elapsedTime > incrementTime)
{
    // Advanced plane one tile
    elapsedTime = 0; // Reset elapsedTime
}
\$\endgroup\$
0
\$\begingroup\$

One cheaty way to do this (means the planes would not be able to be shot down etc.) is to simple store the time the plane started its journey, start and end points. You can then draw this on the client side by simply drawing a line from start point to end point and calculating how far along this line the plane should be.

In terms of finding which flights should be in a given chunk you can use the line co-ordinates against the chunk co-ordinates to see if a user might require that flight.

\$\endgroup\$
1
  • \$\begingroup\$ Please note this is not a "good" solution but one that should be relatively easy to implement :) \$\endgroup\$
    – JackFrost
    Sep 4 '15 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.