I remove indications for body movement, depending on the inclination of the device, the code took off. Input Manual
public float speed; Vector3 dir; // Use this for initialization void Start () { speed = 10.0f; dir = Vector3.zero; } // Update is called once per frame void FixedUpdate () { // пробовал и просто с Update, вроде с физикой лучше использовать Fixed dir.x = Input.acceleration.x; dir.z = Input.acceleration.y; // clamp acceleration vector to the unit sphere //if (dir.sqrMagnitude > 1) //dir.Normalize(); // Make it move 10 meters per second instead of 10 meters per frame... dir *= Time.deltaTime; // Move object transform.Translate(dir * speed); }
Everything works, and it is excellent and responsive, but sometimes, when the bodies touch each other (for example, the player touches the walls and slides along them for a while) something goes wrong and one of the axes is inverted, or starts to move vertically! Jumps player on which the script.