- Home /
Question by
Henoc · Apr 03, 2014 at 01:07 AM ·
positionaccelerometerinput.acceleration
Manipulating accelerometer to get the right position with the viw
Hi , im trying to learn how to work with accelerometer but i have a few questions regarding it
I have this screen, and the red ball will be the one moving
this is the code im using:
public class Done_PlayerController : MonoBehaviour{
public float speed;
public float tilt;
public Done_Boundary boundary;
void FixedUpdate ()
{
void FixedUpdate ()
{
float moveHorizontal = Input.acceleration.x;
//Input.GetAxis ("Horizontal");
float moveVertical = (Input.acceleration.z);
Vector3 movement = new Vector3 (moveHorizontal,moveVertical,0.0f );
rigidbody.velocity = movement * speed;
rigidbody.position = new Vector3
(Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
Mathf.Clamp (rigidbody.position.y, boundary.yMin, boundary.yMax),
0.0f
);
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * >-tilt);
}
}
do i have any prob? tried all afternoon but nothing
1.jpeg
(25.2 kB)
Comment
Your answer
Follow this Question
Related Questions
Input.acceleration reading Issue 1 Answer
iPad: accelerator tilt breaks collider 3 Answers
Smooth tilt accelerometer 1 Answer
Save Matrix 4x4? 1 Answer