Help with trying to make a 2D character move in all four directions via the arrow keys


So recently I have set myself a little project to try and recreate a level from the MSX game known as Metal Gear 2 Solid Snake. I’ve got all the sprites set up, camera placement and 2D settings and such along with the rigidbody2d and colliders where they need to be along with the animations set up and the states of them linked.

What I am struggling with is the script to move the character by pressing any of the four arrow keys. Since the MSX originally was a overhead top down view where you could move in all four directions, I am having trouble trying to set up a script to work with it. Most of the tutorials I have found focus mainly on the side scroller aspect of 2D, which is something I don’t need.

I have little experience with scripting so I may be looking at the wrong tutorials. So any help with this would be appreciated. Thanks.

float H,V;
public float speed;
Rigidbody2D rgb;
void Start(){
rgb = GetComponent();
void Update() {
H = Input.GetAxis(“Horizontal”);
V = Input.GetAxis(“Vertical”);
rgb.velocity = new Vector2(Hspeed,Vspeed);

The concept of Input is usually the same, the implementation might be a bit different, but you should be able to figure out what to do by looking at the sidescroller tutorials.

// top-down movement, using the XZ axises
Vector3 moveVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

Unity - Input.GetAxis

Here I’m using transform.Translate for simplicity, but if your character has a CharacterController component, it might be better to use the 5 or SimpleMove functions instead. If the character has a RigidBody, then setting the velocity or adding force might be the way to go.