How can i detect speed on a mobile

In more detail what i want to do is detect the speed of the player so i can figure out what animation to play and what way the player should be facing for PC i have the current code

		transform.Translate (Input.acceleration.x, 0, 0);// mobile input THIS IS THE MOBILE PART But should use Rigiedbody2D

		float move = Input.GetAxis ("Horizontal");// allows user to change control THIS WILL NOT WORK FIND SOMETHING ELSE PC ONLY
		GetComponent<Rigidbody2D> ().velocity = new Vector2 (move * Max_player_speed, GetComponent<Rigidbody2D> ().velocity.y);// basic movement

		if (move > 0.0f) {// add running right animation here this may not work
			print ("running right"); 

		}

		if (move < 0.0f) {// add running left animation here
			print ("running left"); 
		
		}

so what i need to do is make it so that instead of getting information from Horizontal input but get it from the acceleration input for mobile devices and use the same system.

I fixed my own issue after 9 or so hours of going through forms and help posts and just writing random chunks of code to see if it works i finally came up with the correct solution first the moveing the player with add force rather than transform.Translate (Input.acceleration.x, 0, 0); i used GetComponent<Rigidbody2D>().AddForce(Input.acceleration*Max_player_speed* Time.deltaTime); // mobile input THIS IS THE MOBILE PART Improved

then for finding the the velocity of acceleration i used

float move = Input.acceleration.x;// new float  required to animate player
GetComponent<Rigidbody2D> ().velocity = new Vector2 (move * Max_player_speed, GetComponent<Rigidbody2D> ().velocity.y);

i put my solution here for anybody else has the same issue i did,
also thank you to itsharshdeep for you’re suggestion :slight_smile:

I want the phone to play music while speeding in the car. can i use this code?