Game Development Reference
In-Depth Information
Now that we have a place to move the player to, we just need to add the ability to move
the player once we have selected a target location and get the player moving on his merry
way. So, add the following to the end of the previous Update function:
if (TargetLocation != Vector3.zero && TargetLocation !=
transform.position && TargetLocation != StartLocation)
{
transform.position = Vector3.Lerp(StartLocation,
TargetLocation, timer);
timer += Time.deltaTime;
}
In the preceding code, we simply check whether the user has selected a destination and
check that we are not there already. If everything is fine, then we just keep updating the
player's position using the Lerp function gradually over time.
With that done, simply add the script to the player game object we created in our scene
earlier and run the project.
Although it works, you should instantly see one issue: when the players starts on the map,
they are actually interacting with the place on the map they started from ( Home in this
case). Because it is interacting with that place already, this causes the navigation prompt
to appear and asks them whether they want to go home.
As our player is not a scaredy cat and wants to venture further, let's fix that.
Managing input priorities
When organizing your map navigation, input prioritization is an important point. When
you have both GUI input and player input challenging for control, you should be able to
manage which is currently active at any one time; otherwise, if both are active, you will
get unexpected or duplicate results.
For instance, once you have your player moving using the mouse/touch, then the GUI to
travel to that destination pops up and accepts input in both the GUI and the map move-
ment at the same time. Hence, when you click on a button to travel or stay, then the map
character will also move.
To combat this, the simplest and best way is to reuse our MessagingManager script
with a new message to handle whether the GUI is taking input or the game is.
Search WWH ::




Custom Search