- Home /
How to get highest value for acceleration from Input.gyro
I'm using gyroscope and I need to get highest value for user acceleration (x, y, z axises) from gyroscope
My current code looks like this
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour
{
public Text x, y, z;
void Start()
{
Input.gyro.enabled = true;
}
void Update()
{
x.text = Mathf.Abs(Input.gyro.userAcceleration.x).ToString();
y.text = Mathf.Abs(Input.gyro.userAcceleration.y).ToString();
z.text = Mathf.Abs(Input.gyro.userAcceleration.z).ToString();
}
}
Thanks for any help
Why you not multiple it up? Like this.
z.text = $$anonymous$$athf.Abs(Input.gyro.userAcceleration.z) * speed
And that speed. Just assign this variable.
public float speed = 10;
And you just made button to Increase or Decrease it.
Values of x, y and z are changing every frame. I need to achieve highest value of this 3 axis for later use
Do you need something like for each value sample you are getting you want to store the highest value that was reached?
In that case just create a variable to store the maxValue and for each sample value received check if it is greater than maxValue. If greater then set this sample value to maxValue.
Wait... You want to record highest value?
Try save it to Hashable list. And use Linq $$anonymous$$ax value.
Bit first you need
System.Linq;
System.Collection.Generic;
And here is Variable
Hashable highestZ
Here is add to hash list code
highestZ.Add(Input.gyro.userAcceleration.z);
Here is how to get max value
highestZ.$$anonymous$$ax();
Is that what you want?
Or just do like @Harshad$$anonymous$$ said.
Use an accessor like this
private float _z
public float HighestZ
{
get
{
return _z;
}
set
{
if (value > _z)
{
_z = value;
}
}
}
After that. In update code.
HighestZ = Input.gyro.userAcceleration.z;
First of all many thanks to all of You for trying to help me.
I'm trying to develop an app that can detect car acceleration, braking and cornering speed. I need to detect device acceleration. Is that acceleration high or low?. Like flo app on Google Play
Your answer
Follow this Question
Related Questions
Detect car acceleration with device motion sensors and GPS 0 Answers
How do I access the Accelerometer and Gyroscope on my Surface Pro? 2 Answers
GameObject dosen't move 2 Answers
Get absolute acceleration data from accelerometer/gyroscope but neglect rotational acceleration 1 Answer
How to judge intensity of shaking in android phones 1 Answer