Challenge - 5 Problems
Smooth Movement Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
Think about how Input.GetAxis works compared to Input.GetAxisRaw.
✗ Incorrect
Input.GetAxis returns a value that changes smoothly from 0 to 1 when pressing a key, allowing smooth movement. It does not jump immediately to 1.
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
Input.GetAxisRaw returns raw input without smoothing.
✗ Incorrect
Input.GetAxisRaw returns -1 immediately when pressing left arrow, no smoothing.
🔧 Debug
advanced2: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);
Attempts:
2 left
💡 Hint
Think about how input smoothing affects movement feel.
✗ Incorrect
Using Input.GetAxisRaw causes instant input changes, which can make movement feel jerky compared to smooth input.
🧠 Conceptual
advanced2:30remaining
How to achieve smooth acceleration using input axis?
Which approach best achieves smooth acceleration and deceleration for player movement in Unity?
Attempts:
2 left
💡 Hint
Smooth input and frame-rate independent movement are key.
✗ Incorrect
Using Input.GetAxis provides smooth input values, and multiplying by Time.deltaTime ensures smooth movement regardless of frame rate.
❓ Predict Output
expert3: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;
Attempts:
2 left
💡 Hint
Consider variable scope and how 'velocity' is updated each frame.
✗ Incorrect
The variable velocity is reset to 0 every frame because it is declared inside Update(). So it never accumulates.