0
0
Unityframework~20 mins

Input axis for smooth movement in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Smooth Movement Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Unity C# code for horizontal input?
Consider the following Unity C# script snippet inside Update(). What will be the value of moveHorizontal if the player presses the right arrow key for a short moment?
Unity
float moveHorizontal = Input.GetAxis("Horizontal");
Debug.Log(moveHorizontal);
AAlways 1 immediately when the key is pressed
BA value smoothly increasing from 0 to 1 over a short time
CAlways 0 regardless of input
DA value instantly jumping between -1 and 1 with no smoothing
Attempts:
2 left
💡 Hint
Think about how Input.GetAxis works compared to Input.GetAxisRaw.
Predict Output
intermediate
2:00remaining
What does this code print when pressing left arrow key?
Given this code snippet inside Update(), what will be printed when the player presses the left arrow key?
Unity
float moveHorizontal = Input.GetAxisRaw("Horizontal");
Debug.Log(moveHorizontal);
AAlways 0 regardless of input
BA value smoothly changing from 0 to -1
CA value of -1 immediately when the key is pressed
DA value of 1 immediately when the key is pressed
Attempts:
2 left
💡 Hint
Input.GetAxisRaw returns raw input without smoothing.
🔧 Debug
advanced
2:30remaining
Why does this movement feel jerky?
This Unity C# code moves a player horizontally using Input.GetAxisRaw. Why might the movement feel jerky?
Unity
float move = Input.GetAxisRaw("Horizontal");
transform.Translate(move * speed * Time.deltaTime, 0, 0);
ABecause Input.GetAxisRaw returns values instantly without smoothing, causing sudden jumps
BBecause Time.deltaTime is not used, causing inconsistent movement
CBecause transform.Translate is called outside Update, causing lag
DBecause speed is multiplied twice, causing too fast movement
Attempts:
2 left
💡 Hint
Think about how input smoothing affects movement feel.
🧠 Conceptual
advanced
2:30remaining
How to achieve smooth acceleration using input axis?
Which approach best achieves smooth acceleration and deceleration for player movement in Unity?
AUse Input.GetAxisRaw and add a fixed value to position each frame
BUse Input.GetAxisRaw and multiply by speed without Time.deltaTime
CUse Input.GetAxis and set position directly without Time.deltaTime
DUse Input.GetAxis and multiply by speed and Time.deltaTime in Update
Attempts:
2 left
💡 Hint
Smooth input and frame-rate independent movement are key.
Predict Output
expert
3:00remaining
What is the value of 'velocity' after this code runs?
Given this Unity C# code snippet inside Update(), what is the value of velocity after pressing right arrow key for 1 second continuously? Assume speed = 5f and frame rate is 60 FPS.
Unity
float moveInput = Input.GetAxis("Horizontal");
float velocity = 0f;
velocity += moveInput * speed * Time.deltaTime;
AAlways 0 because velocity is reset each frame
BExactly 5 immediately after pressing the key
CApproximately 0.0833 (5 * 1/60) after one frame, accumulating over frames
DApproximately 1 after one second
Attempts:
2 left
💡 Hint
Consider variable scope and how 'velocity' is updated each frame.