How do I find the current velocity of a rigidbody2D C#

How do I find the current velocity/speed of a rigidbody2D on an Enemy object on the x Axis i have tried working on it by myself but find i need help from the community i am using a flip function to save time on animations and flip the sprite
this is what i have so far

	void FixedUpdate ()
	{
		 //handles caracter direction based on speed
		float move = rigidbody2D.velocity.magnitude; // FIX ME I DONT KNOW HOW TO FACE THE PLAYER
		if (move > 0 && facingLeft)
			Flip ();
		else if(move <0 && !facingLeft)
			Flip ();
		}

if anyone can provide me with the fix to this problem it would be very much appreciated :slight_smile:

You can check the velocity along x axis to find out the direction in which your character is facing as below:

void FixedUpdate ()
{
	//handles caracter direction based on speed
	float move = rigidbody2D.velocity.magnitude; // FIX ME I DONT KNOW HOW TO FACE THE PLAYER
	if (move > 0 && transform.InverseTransformDirection(rigidbody2D.velocity).x < 0) // If your character is facing left then his movement velocity will be negative in local space
		Flip ();
	else if(move <0 && transform.InverseTransformDirection(rigidbody2D.velocity).x > 0)  // If your character is facing right then his movement velocity will be positive  in local space 
		Flip ();
}

OR

Another method is to use a boolean that indicates the direction that you switch each time you make your character flip.

bool isfacingLeft = false; // This indicates you start facing right

void FixedUpdate ()
{
	//handles caracter direction based on speed
	float move = rigidbody2D.velocity.magnitude; // FIX ME I DONT KNOW HOW TO FACE THE PLAYER
	if (move > 0 && isfacingLeft)
		Flip ();
	else if(move <0 && !isfacingLeft)
		Flip ();
}

void flip()
{
	// Your other code to flip goes here.
	// Switch the facing directioin to indicate in which direction it is facing
	isfacingLeft = !isfacingLeft;
}