- Home /
Gyroscope default position
I have a question about gyroscope delault position. I created a game in witch you move space ship foward, back, left, and right by moving the phone(using gyroscope). My problem is that I must hold phone like on picture 1. If i hold the phone like on picture 2, the ship goes down. Anyone know how to change default position of the gyroscope, so I can normally hold the phone and steering the ship? I want the ship stationary if my phone is holded at 45 degrees. Otherwise, it move to the titled direction.
My code:
using UnityEngine; using System.Collections;
[System.Serializable] public class Boundaryy { public float xMin, xMax, zMin, zMax; }
public class PlayerControll1 : MonoBehaviour { public float speed; public float tilt; public Boundaryy boundary;
// Use this for initialization
void Start () {
Input.gyro.enabled = true;
Screen.sleepTimeout = SleepTimeout.NeverSleep;
}
void FixedUpdate() {
float xi = Input.gyro.userAcceleration.x;
float yi = Input.gyro.userAcceleration.y;
Vector3 movement = new Vector3 (xi, 0.0f, yi);
rigidbody.velocity = movement * speed;
rigidbody.position = new Vector3
(
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
);
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
}
}
Answer by hav_ngs_ru · Jan 19, 2015 at 03:47 PM
...
Vector3 movement = new Vector3 (xi, 0.0f, yi);
movement = Quaternion.AngleAxis(45, Vector3.right) * movement; // <<< ADD THIS
...
EDIT: just corrected my silly mistake :)))
Nah, not working. The ship don't go down to the bottom.
I want the ship stationary if my phone is holded at 45 degrees. Otherwise, it move to the titled direction. If you know what I mean :)
arrrh! sorry, my silly mistake :)) try new code (edited in original answer)
Tryed it and it's still not working... $$anonymous$$y space ship is unfortunately not standing still at 45 degrees, but again in 0 (like Picture 1)...
have you placed it before **rigidbody.velocity = movement speed;* ?
Answer by MarlonH · Jan 20, 2015 at 11:28 AM
Change the local rotation with the gyro and set this object to a parent. Use the global rotation of the object :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613180838im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
View an array of the transform position/rotation of all game objects with a specified tag., 0 Answers
How read tag in the animator? 0 Answers
FindGameObjectWithTag failing 1 Answer
OnTriggerEnter Glitch 1 Answer
Tag list emptied!? 1 Answer