Hello
I'm trying to make my first Unity AR project using Vuforia.
I want to create a maze with ball in it. A problem is that I want to move a ball with accelerometer. I almost made it however each time camera detects marker I would like to take accelerometer parameters to save current orientation of phone as initial. If I don't do that I will have to keep my phone as it was on flat plane.
I past my script below.
Waiting for your help :)
private float moveHorizontal, moveVertical, initHorizontal, initVertical;
private float speed = 10.0f;
void Start()
{
rigid = GetComponent();
initHorizontal = Input.acceleration.x;
initVertical = Input.acceleration.z;
}
void Update()
{
moveHorizontal = Input.acceleration.x - initHorizontal;
moveVertical = Input.acceleration.z - initVertical;
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigid.AddForce(movement * speed * 2);
}
↧