You're exploring a demo with made-up sample data — no real student information is shown.

Back to assignments
Code Due May 8

Player Movement Script

C# Scripting · 25 points

Instructions

Write a PlayerController that reads keyboard input and moves the player in four directions at a configurable speed. Keep movement smooth and frame-rate independent.

Your code

PlayerController.cs

1using UnityEngine;
2
3public class PlayerController : MonoBehaviour
4{
5 public float speed = 5f;
6
7 void Update()
8 {
9 float h = Input.GetAxis("Horizontal");
10 float v = Input.GetAxis("Vertical");
11
12 Vector3 move = new Vector3(h, 0f, v);
13 transform.Translate(move * speed * Time.deltaTime);
14 }
15}
(disabled in the demo)

Submitted— your teacher hasn't graded this yet.