Is there any way I can involve "Horizontal" and "Vertical" in a movement script " in a script involving rigidbody2d?

if (Input.GetKey(KeyCode.D)){

		rigidbody2D.AddForce(Vector2.right * movespeed);
	if (Input.GetKey(KeyCode.W)){
		rigidbody2D.AddForce(Vector2.up * movespeed);
	if (Input.GetKey(KeyCode.A)){
		rigidbody2D.AddForce(-Vector2.right * movespeed);
	if (Input.GetKey(KeyCode.S)){
		rigidbody2D.AddForce(-Vector2.up * movespeed);

This is the script and I want to able to make it work with my controller using “horizontal” and “vertical”.

float horiz = Input.GetAxis(“Horizontal”);
float vert = Input.GetAxis(“Vertical”);
rigidbody2D.AddForce ( new Vector2( horiz, vert ) * moveSpeed );

Note that technically speaking, you should only call the AddForce family of methods in FixedUpdate, and only gather input during Update. In the interest of showing best practices…

Vector2 input;
void Update() {
  input.x = Input.GetAxis("Horizontal");
  input.y = Input.GetAxis("Vertical");
void FixedUpdate() {
  rigidbody2D.AddForce( input * moveSpeed );