- Home /
gyroscope script problem.
Hello, all. I have a question, about a script with a gyroscope. I have this script:
var xForce : float = 10;
var yForce : float = 10;
var zForce : float = 10;
static var rotationRate : Vector3;
function Update (){
if (Gyroscope.rotationRate(1,0,0)) rigidbody.AddForce(Vector3(0, 0, 10));
if (Gyroscope.rotationRate(0,1,0)) rigidbody.AddForce(Vector3(10, 0, 0));
if (Gyroscope.rotationRate(-1,0,0)) rigidbody.AddForce(-Vector3(0, 0, 10));
if (Gyroscope.rotationRate(0,-1,0)) rigidbody.AddForce(-Vector3(10, 0, 0));
}
But unity gives a error:
Assets/scripts/marble controle (gyroscope).js(15,15): BCE0020: An instance of type 'UnityEngine.Gyroscope' is required to access non static member 'rotationRate'.
What do have to do with it? Ty, already.
[Edit by Berenger : I formatted you code properly, but line 15 might not be relevant anymore.]
Answer by Starwalker · Jun 04, 2012 at 07:45 PM
Gyroscope.rotationRate returns a Vector3 from the device's Gyro, your assigning a Vector3 to the gyroscope which is what is causing a prob.
You can try this:
var GyroVector : Vector3;
GyroVector = Input.gyro.rotationRate;
This GyroVector should have the 3 Vectors you want.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Items with Statistics(such as attack damage) that actually effect the character? 2 Answers
Delete object when two collision or more 1 Answer
Reloading Help 2 Answers