- Home /
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?
no one have the solution for my answer??? I thought this is the place of the awesome developers and I can get my solution.... but in vain....
Well, we kinda help people with real problems, and not those too lazy to look for their own answers. I'll be kind and help you on this occasion.
Answer by Graham-Dunnett · Apr 16, 2013 at 03:35 PM
Sounds like you need to use a Gyroscope. In Unity use `Input.gyro` to get access to the device's gyroscope.
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.
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.
Graham thanks, your comment and answer really helped me and because of that I increased my capacity of thinking and logic furthermore. I am hungry of program$$anonymous$$g and you helped me to have it.... Thanks buddy
Answer by Tawakal125 · Dec 30, 2019 at 10:52 AM
tenthplanet0
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;
}