SCREEN SPACE
With already-covered concepts, can move at a
constant speed in a specified direction.The movement is not dependent on framerate, so it looks the same regardless of the user's platform. Our current goal is for to move to a user-clicked location. Capturing mouse-click information uses Screen Space: Screen Space Attributes
A Simple Script to Understand Screen Space
|
(1) the script a text file containing this UnderstandingScreenSpace code |
The screen is dark blue. My four approximate clicked corners are shown. |
sample console output Starting Mouse Position gives the Screen Space coordinates of my Play button.I left-mouse-clicked the four (approximate) screen corners, in this order: (1) lower left corner (2) upper left corner (3) upper right corner (4) lower right corner |
CAMERAS
For reference:
Basic Information on Cameras
|
(1) Uncheck the component. When there's no active camera, then nothing is visible! (For understanding the next script, take note of the MainCamera tag!)
|
MOVE TO A USER-CLICKED LOCATION
This is our first script to use the class.
Then, almost all the code in (1) is familiar. Here are the new concepts:
Try It!
Play the game!Click anywhere, and watch move to that location. You can adjust the speed with the public variable. How cool is that? |
(1) the script a text file containing this MoveToClickedLocation code |
A CLOSER LOOK AT THE PREVIOUS SCRIPT
You might be curious as to why we didn't just use
in our script.Try it—change to as shown in (1) at right. Unless you make other compensating changes, you'll see move towards its first target ... and disappear, never to be seen again (until you stop playing the game)! Some added statements reveal what's happening. See (2a) and (2b) below.
|
(1) Make some changes to the script: change to ; add the two indicated lines. |
(2a) Wolf starts moving towards its target position ... |
(2b) ... and arrives! |