So, I’ve just completed the Space Shooter tutorial and I’m really happy to have successfully created the game according to specs. Just for grins and giggles I decided to remake the game with my own art and sound. This came out fairly well. The thing is, I set my target to iOS because I wanted to attempt porting the game, which relies on WASD control input, for use on my iPad. I am stuck as can be though when it comes to changing the whole Input class over to receive accelerometer input. I watched the official video, and the code there is quite simple, except that it only applies to non-rigidbodys. My Player GameObject is a rigid body. The code used in the tutorial is:
//movement
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
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);
//movement
}
I felt like I totally understood this when I ran through the tutorial, but when I look at the code in the script reference documentation for Acceleration Input I see all kinds of things I don’t recognize: “dir” and “cali” and such. I’m not asking for free code, but I can’t seem to find a good step by step tutorial. Can someone point me in the right direction? I don’t mind teaching myself through good documentation…I just can’t seem to find it. =-(
Long story short, I would like to know who to detect accelerometer input, and use that input to apply force to my rigidbody player GameObject.