using UnityEngine;
public class TopDownCharacterController : MonoBehaviour
{
// Define movement speed and reference to Rigidbody2D component
public float movementSpeed = 5f;
private Rigidbody2D rb;
void Start()
{
// Get reference to Rigidbody2D component
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
// Get input from arrow keys or WASD keys
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
// Calculate movement direction based on input
Vector2 movementDirection = new Vector2(horizontalInput, verticalInput).normalized;
// Move character based on movement direction and speed
rb.velocity = movementDirection * movementSpeed;
}
}