Change Agent: Disable keyboard camera controls
We think that one of the coolest features of StarLogo TNG is that you can fly around SpaceLand while your model is running. In aerial mode (the airplane button), you can use your mouse or the keyboard to pan the scene, rotate for the right angle, and zoom in for a better view.
Unfortunately, controlling the camera with the keyboard conflicts with another cool feature-- namely, controlling agents with the keyboard. To see what I mean, let's build a model that does just that (or download it).
First, we'll make a procedure called Move that checks whether a key is down, and, if it is, moves the agent forward one step in that compass heading. Note that since we're using if blocks instead of if-else blocks, the procedure can detect when we press more than one arrow key at the same time to make the agent move on a diagonal.
Next, drag out a Forever block and call the Move procedure we just created.
Finally, let's setup the model to create a single turtle agent in the center of SpaceLand.
Great! Now click the Runtime tab, where you'll see two buttons called Setup and Forever. Click the Setup button to create our single turtle in the center of the screen, then click Forever to start the model. Now, use the arrow keys to move the agent around.
Uh-oh. While you may be able to tell that the agent is moving in response to your key presses, you were probably more distracted by the camera moving around too. Sure, you could switch camera modes to the 2D top-down view, or perhaps use the the over-the-shoulder perspective, but what if you really want to keep the model running in aerial mode?
Fortunately, there's a menu item tucked away under Options called "Keyboard moves camera." If you look at it, you'll see a checkmark next to it, which indicates that, yes, in fact, the keyboard is controlling the camera (but we already knew that).
In the next release we intend to make this option more visible, but for now, all we have is the menu item. So choose Options... Keyboard moves camera, and the next time you look at the Options menu, you'll see that the checkmark is gone. The keyboard no longer controls the camera, and you are free to use all those keys in your model to control agents. Go ahead, try it!
Unfortunately, controlling the camera with the keyboard conflicts with another cool feature-- namely, controlling agents with the keyboard. To see what I mean, let's build a model that does just that (or download it).
First, we'll make a procedure called Move that checks whether a key is down, and, if it is, moves the agent forward one step in that compass heading. Note that since we're using if blocks instead of if-else blocks, the procedure can detect when we press more than one arrow key at the same time to make the agent move on a diagonal.
Next, drag out a Forever block and call the Move procedure we just created.
Finally, let's setup the model to create a single turtle agent in the center of SpaceLand.
Great! Now click the Runtime tab, where you'll see two buttons called Setup and Forever. Click the Setup button to create our single turtle in the center of the screen, then click Forever to start the model. Now, use the arrow keys to move the agent around.
Uh-oh. While you may be able to tell that the agent is moving in response to your key presses, you were probably more distracted by the camera moving around too. Sure, you could switch camera modes to the 2D top-down view, or perhaps use the the over-the-shoulder perspective, but what if you really want to keep the model running in aerial mode?
Fortunately, there's a menu item tucked away under Options called "Keyboard moves camera." If you look at it, you'll see a checkmark next to it, which indicates that, yes, in fact, the keyboard is controlling the camera (but we already knew that).
In the next release we intend to make this option more visible, but for now, all we have is the menu item. So choose Options... Keyboard moves camera, and the next time you look at the Options menu, you'll see that the checkmark is gone. The keyboard no longer controls the camera, and you are free to use all those keys in your model to control agents. Go ahead, try it!
Labels: change agent, spaceland
1 Comments:
useful info. I'll direct my students to this blog
Post a Comment
<< Home