# Input.GetAxisRaw isnt being called?

I have a script that takes user input from the horizontal and vertical axes via Update, stores them in 2 floats, moveX and moveY, and calculate velocity of the rigidbody2D via FixedUpdate. the calculation is done in a separate function. I first calculate the velocity along the x axis and then the velocity along the y. While the Y is getting registered, the x isnt. I swapped up the order in which the calculation is done and the condition swapped as well; now x is being registered while y isnt. Help!

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D rb2d;
float moveX;
float moveY;
public float moveSpeed;

private void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}

private void Update()
{
moveX = Input.GetAxisRaw("Horizontal");
moveY = Input.GetAxisRaw("Vertical");
}

private void FixedUpdate()
{
CalculateVelocity();
}

void CalculateVelocity()
{
if (moveX != 0)
{
rb2d.velocity = Vector2.right * new Vector2(moveX, rb2d.velocity.y) * moveSpeed;
}
else rb2d.velocity = Vector2.zero;

if (moveY != 0)
{
rb2d.velocity = transform.up * new Vector2(rb2d.velocity.x, moveY) * moveSpeed;
}
else rb2d.velocity = Vector2.zero;
}
}
``````

You multiple `rb2d.velocity` by either `Vector2.right` or `transform.up`. Both of these vectors resets one axis to zero. It’s becuase:

`Vector2.right = new Vector2(1, 0);`

`transform.up = new Vector2(0, 1);` or `transform.up = new Vector2(0, -1);` (or something different if the game object is rotated)

The fix to your problem should be simple as writing something like this instead:

``````rb2d.velocity = new Vector2(
moveX * moveSpeed,
moveY * moveSpeed
);
``````