player move based on tilt of the mobile device... movement of the spawned item in rounded way like subway surfer

hiiii developers,

I want the help in two things

  1. I want to move my player based on the tilt of mobile device. So how can I detect whether the device is tilted right, left, straight(normal), front and back?

  2. another thing is I want the movement of my front spawned path or simple path in rounded fashion. So, how can I achieve that? subway surfer is the example like what I want to achieve…

I have one more question… in temple run 2 the character is jumping and when he is touching the rope then he is moving along with the rope and also on mobile tilt rotating right and left. So, how can we achieve that?

  1. Sounds like you need to use a Gyroscope. In Unity use Input.gyro to get access to the device’s gyroscope.
  2. Use splines to define the curved paths. Now in your code “forward” means to move in the direction of the spline, and left and right means tangentially to the spline.
  3. If the rope is a spline, then you can compute the shortest distance of the player to the spline. This distance will be perpendicular to the spline, so in reality you’re also computing where on the spline this shortest distance reaches. Then, when your player jumps, you can compute how close to the spline he gets. If you are within some distance, then in your code your player can travel along the rope.


void Start()
rb = GetComponent();

void FixedUpdate()

   //  horizontal movement code through device rotation

          var movement = new Vector3(Input.acceleration.normalized.x, 0.0f, 0.0f);
          rb.velocity = movement * speed;