Placing Objects
Learn to place, hide, and use the force on items
Learning Objectives
We should now have some basic character movement, maps, and other attributes of our game setup. For the next few lessons, our goal is to get a quest up and running. Notably, our goals are to 1) place items that we will use in a quest, and then to 2) get those items in code and tell our running scene to hide them. The reason we are doing this is because we are going to later have our NPC make them magically appear on the screen for our character to go get them.
You will:
- Learn how to hide items in a game
- Learn about Vectors
- Learn to use the force
Place Items in the Scene (10 minutes)
In our quest, we want our NPC to go have to collect items. Decide what items you want displayed on the screen and place no more than 5-10 of them on your map. Each one should be given a unique name in the property field. We recommend giving them names with a logical incremental ending, like Blue potion 1 and Blue potion 2. This is because in later lessons we will use this property to our advantage.
Hide the Items (20 minutes)
Now that we have items in the scene, we want them to disappear. The idea is that our NPC is telling us to go find something that they need, which we expose to the player. However, if we load our game right now, these items will show up right away in our game, so we need to hide them. To do this, we 1) in our CreateGame action, find each item like we did before with our character, then 2) for each item, find an action related to showing or hiding the item and call this property. Finding what action to call is an important part of computer science, so practicing looking through documentation can be a helpful way to practice our skills.
Apply Physics to Character Movement (20 minutes)
Now that we have items in our scene and they are hidden, let us go back to our character to clean up the way our character moves. Notably, let's get our character to use physics to move up and down. To do this, we need to learn about the concept of vectors from math and to send vectors to our character's physics system. This will automatically make our character move in a way that adjusts to our map. For example, our character will be able to walk on dirt, but not on water. The 2D physics tutorial on using the 2D force or using the 3D force can both defeat sith lords and is helpful for our programming.
Wrap-up (10 minutes)
For discussion in this lesson, attempt an experiment: move your character around the map and bump into things. Notice that 1) if you move, you keep moving forever, and 2) if you hit corners you can sometimes spin out of control. Can your group come up with a strategy, by looking at the actions we can call on our character, to change these behaviors in our game?
Next Tutorial
In the next tutorial, we will discuss Making Objects Good and Evil, which describes place items and use code to give them properties..