2d Game Movement: Enemy is Moving Diagonally vertical instead of vertically straight

Hello, my enemy is walking properly with no problem in the x direction, for they are walking smoothly and perfectly straight in the x-axis, but my enemies are walking diagonally vertical instead of vertically straight in the y-axis for whatever reason. Here is the code I have so far:

hittingTree = Physics2D.OverlapCircle (treeCheck.position, treeCheckRadius, whatIsTree);

if (hittingTree)
moveUp = !moveUp;

if (moveUp) {
myAnimator.Play (“goblinUpMovement”);
transform.localScale = new Vector3 (4f, 4f, 4f);
enemyRigidbody.velocity = new Vector2 (moveSpeedY, enemyRigidbody.velocity.x);
} else {
myAnimator.Play (“goblinDownMovement”);
transform.localScale = new Vector3 (4f, 4f, 4f);
enemyRigidbody.velocity = new Vector2 (-moveSpeedY, enemyRigidbody.velocity.x);
}

the enemy is switching between the two animations just fine but it still won’t want to move vertically straight. When I try to constraint its x axis movement, it has this gritty kind of movement where it moves extremely slow and unnatural unlike my horizontal movement which is fluid and smooth. could it be something else?

P.S. Here is the code for the x-axis:

hittingTree = Physics2D.OverlapCircle (treeCheck.position, treeCheckRadius, whatIsTree);

if (hittingTree)
moveRight = !moveRight;

if (moveRight) {
transform.localScale = new Vector3 (-4f, 4f, 4f);
enemyRigidbody.velocity = new Vector2 (moveSpeed, enemyRigidbody.velocity.y);
} else {
transform.localScale = new Vector3 (4f, 4f, 4f);
enemyRigidbody.velocity = new Vector2 (-moveSpeed, enemyRigidbody.velocity.y);
}

There is a pinned thread in the forums about how to use code tags/insert code properly formatted. Please read that and update your post (and for future posts*).

Are you possibly mixing up the x & y in your Up/down code?
the New Vector2(Xmove, Ymove) should be in that order…
If you want zero Xmovement, just put zero in the first paramter there.