Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Game Development How to Make a Video Game Player Input and Cameras Move the Player with Animation

Timothy Van Cauwenberge
Timothy Van Cauwenberge
8,958 Points

How does the computer know to only use the arrow keys and not just any button on the keyboard?

How does the computer know to only use the arrow keys and not just any button on the keyboard?

1 Answer

This is largely determined by the script attached to the object that you intend to move with the arrow keys. In the script you would tell the object to move in the direction that you want it to move whenever a specific key is pressed. In this project we used the word "Horizontal" and "Vertical" to determine what keys to gather information from. The word "Horizontal" gathers information from the left and right keys and the word "Vertical" gather information from the up and down keys. Once we have this value we can assign it to the game object to move in the direction that the key is pressed. Unity assigns the word horizontal and vertical to the specific keys by default and you can see this in the Input panel located in the Project Settings option of the Edit Menu.