- Home /
Nexus S, accelerometer.
Hello, all. I have a question. I have this basic script of a marble game (down here). var xForce : float = 10; var yForce : float = 10; var zForce : float = 10;
function Update () {
if (Input.GetKey ("up"))
rigidbody.AddForce(Vector3(0, 0, 10));
if (Input.GetKey ("right"))
rigidbody.AddForce(Vector3(10, 0, 0));
if (Input.GetKey ("down"))
rigidbody.AddForce(-Vector3(0, 0, 10));
if (Input.GetKey ("left"))
rigidbody.AddForce(-Vector3(10, 0, 0));
}
But i really have any experience with the accelerometer. How does an accelerometer thing start? Is it like: Input.accelerometer or something? Anyone know how to do this? Ty, already.
Answer by ina · May 28, 2012 at 09:45 AM
If you check out the iPhone Roll-a-Ball demo, that seems like exactly what you need.
http://unity3d.com/support/resources/example-projects/iphone-examples
As for how to poll for Input.acceleration values... there's a succinct script on the manual page http://unity3d.com/support/documentation/ScriptReference/Input-acceleration.html
Answer by hirenkacha · May 28, 2012 at 10:29 AM
for left right movement use, dont use this inside if condition it will directly check your movments.
rigidbody.AddForce(Vector3(10*Input.acceleration.y, 0, 0));
Your answer
Follow this Question
Related Questions
script linking 1 Answer
problem at adding script 1 Answer
How do I get my "dashing" animation to work? 1 Answer
How to make a N-S magnet Javascript? 1 Answer
How do I make a sword swing? 2 Answers