Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Vagonn · Apr 05, 2016 at 07:05 AM · c#accelerometeraccelerationgyroscopegyro

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

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Toon_Werawat · Apr 05, 2016 at 08:00 AM 0
Share

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.

avatar image Vagonn Toon_Werawat · Apr 05, 2016 at 09:00 AM 0
Share

Values of x, y and z are changing every frame. I need to achieve highest value of this 3 axis for later use

avatar image HarshadK · Apr 05, 2016 at 09:27 AM 1
Share

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.

avatar image Toon_Werawat · Apr 06, 2016 at 11:50 AM 1
Share

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;
avatar image Vagonn · Apr 07, 2016 at 06:22 AM 0
Share

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

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

123 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges