Initial accelerometer parameters to move a ball using Vuforia AR
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<Rigidbody>();
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);
}
Answer by xxmariofer · Sep 20, 2019 at 08:08 AM
check this tutorial for knowing how to get tracking events in vuforia, then you will only have to save hte input.acceleration in a value and use that instead of the current acceleration
Answer by jakubkoscien · Sep 20, 2019 at 08:14 PM
Hey
Thanks for joining the discussion however I don't see any connections between my problem and that tutorial. Anyway I've fixed my problem by changing axis which I get input from (z->y).
how is ever changing the axis help you saving the axis? if you want to save the orientation qhen you track the image you need to get the event to know when you track the image, and thats whats the tutorial is about
Your answer
Follow this Question
Related Questions
Move rolling ball roll forward based on the direction it is facing 0 Answers
apply z-axis friction on 2d game 0 Answers
Function overloading with and optional arguments 1 Answer
Awake alternative for UI button (On-Off) 1 Answer
Can I make a prefab have different sprites based on what direction it is facing? 1 Answer