I want to create a 2D Platformer with a map screen, and I’m halfway through a 3D tutorial so I don’t think 2D development will have much of a learning curve. However, the map screen completely eludes me.
Here’s a glimpse of how the end-product should look:
![alt text][1]
Here’s what I think I need to do:
-
Create a box and apply the map texture to it
-
Create a transparent box for each location and place them at the same XY coords as their resepective settlements on the texture and tag the boxes as ‘Plip’, ‘Peacemas’ ect…
-
Create a box and apply the character texture to it
However, that is the limit of my knowledge. I need to be able to do the following:
-
Place the character on a town based on his current location. I don’t think that’s too hard. We log the location where the character is, and then search for that location and then place the character at the same coords. (lower z axis to prevent pixel-fighting)
-
Detect the quickest route to a location. By quickest I don’t really mean by distance, I mean by the least number of locations we need to pass through. I’m thinking the best way to do this would be to manually create tracks between all the locations:
![tracks][2]
Here’s what I think I need to do:
-
Create a box and apply the map texture to it
-
Create a transparent box for each location and place them at the same XY coords as their resepective settlements on the texture and tag the boxes as ‘Plip’, ‘Peacemas’ ect…
-
Create a box and apply the character texture to it
However, that is the limit of my knowledge. I need to be able to do the following:
-
Place the character on a town based on his current location. I don’t think that’s too hard. We log the location where the character is, and then search for that location and then place the character at the same coords. (lower z axis to prevent pixel-fighting)
-
Detect the quickest route to a location. By quickest I don’t really mean by distance, I mean by the least number of locations we need to pass through. I’m thinking the best way to do this would be to manually create tracks between all the locations:
Is this functionality present in Unity? Does this “track” approach have a name? If it does, it would be a somewhat simple affair to detect which track has the least number of locations on it and return that as the track we’re going to travel along.
Here’s where I’d really appreciate some pseudo-code though, guys. I mean, this is so much easier said than done.
Let’s say we are in Plip and we want to get the Turvail Trail. The quickest this can be done is by passing through 2 locations. One of these could be:
Plip > Field Whar Battles Hap'n > Great Squid Lake > Turnvail Trail
How do we get our character to hop onto track a, then b, then d? My thoughts of the process when a player says they want to travel to Turvail Trail:
-
We need a loop to return an array with the tags of the tracks we need:
[‘a’,‘b’,‘d’,‘e’]
-
Not sure how this loop would look (ideas please!). I think each track needs an attribute that stores the position of the end location they end in. Let’s call this attribute
end_location. I think each location should store the tracks that lead out from it. Let’s call this attributelocation_tracks. Something like this maybe:
var requested_location // 'Turvail Trail'
var current_location // 'Plip'
if(current_location != requested_location ){
var tracks = current_location.location_tracks //[a,f,g]
for(var i = 0; tracks.length; i++){
// and this is where I run out of steam.
// this loops needs to select which track [a,f,d] is the best start to our journey.
// It would actually be easier if we were doing it by distance rather than how many
// locations we need to pass through, then we could use this function to log the
// track that ends up nearest our nearest location:
// Vector3.Distance(tracks*.end_location, requested_location);*
}
}
Something like that.Just need some ideas guys. Unity beginner so I don’t want to dive in if this is a simple solution Unity has already taken care of.
____
- We finally need to travel along our array ['a','b','d','e']. Should this all be done in the Update function?
____
private var route : array; // [‘a’,‘b’,‘d’,‘e’]
private var i : integer = 0;
private var last_route : gameObject;
function Update(){
FollowTrack( route );
if(character.position == array[i + 1].position){
i++;
}
}
function FollowTrack(track_to_follow){
if(last_route !== track_to_follow){
// causes the character object to travel along the route passed to it
last_route = track_to_follow;
}
}
This is all just pseduo-code to give you an idea. Thanks
_[1]: http://i.stack.imgur.com/sTQRp.jpg*_
_[2]: http://i.stack.imgur.com/XeClq.jpg*_