Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 corax · Aug 19, 2013 at 05:40 PM · dragrotate objectaccelerometer

Accelerometer and drag

I'm trying to spin an object that must retain the force applyed by the accelerometer for quite some time. For some reasone the code is not working even if the same come works very well with swipes.

 using UnityEngine;
 using System.Collections;
 
 public class GyroControls : MonoBehaviour 
 {
 
     public GameObject m_objectToMove;
     public GameObject m_sphereBackground;
     public float drag = 1f;
     
     private float _rotValue = 0;
     
     
     public static GyroControls Instance{set;get;}
     
     void Awake () 
     {
         // First we check if there are any other instances conflicting
         if(Instance != null && Instance != this)
         {
             // If that is the case, we destroy other instances
             Destroy(gameObject);
         }
 
         // Here we save our singleton instance
         Instance = this;
 
         // Furthermore we make sure that we don't destroy between scenes (this is optional)
         DontDestroyOnLoad(gameObject);
     }
 
     
     
     void FixedUpdate() 
     {
         ProcessInput(Input.acceleration);
         ProcessMotion(Time.deltaTime);
         ProcessPhysics(Time.deltaTime);
     }
     
     
     
     void ProcessInput(Vector3 dir)
     {    
         _rotValue += dir.x;
     }
 
     
     
     void ProcessMotion(float deltaTime)
     {
         float _turnValue = _rotValue  * deltaTime;
         
         m_objectToMove.transform.Rotate(new Vector3(0,0,_turnValue));
         m_sphereBackground.transform.Rotate( new Vector3(0,0,_turnValue));    
     }
     
     void ProcessPhysics(float deltaTime)
     {
         
         // drag must be improved as function of _rotValue
         
         if(_rotValue < -clamp)
                 _rotValue += drag;
         else if(_rotValue > clamp)
                 _rotValue -= drag;
     }
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Aug 19, 2013 at 06:03 PM

I'm going to take a guess here. I've only played with the an accelerometer a couple of times, and I don't have my Mac setup here to test my theory. An accelerometer should measure a change in velocity. So if I spin the device around I'm going to get some value as I speed up. If I then continue to rotate at the same speed, the acceleration will drop to zero (i.e. the velocity is not changing). As I stop spinning, I'm going to get an equal and opposite acceleration to the one I had to start with when I started spinning.If that is what you see with your accelerometer with then this line:

 _rotValue += dir.x; 

will increase as I start to rotate, but will drop back to something close to zero as I come to a stop. As I come to a stop, the opposite acceleration will counteract any acceleration I had when I started spinning. That is different than a swipe which will just stop inputting as you lift the finger.

Comment
Add comment · Show 1 · Share
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 meat5000 ♦ · Dec 01, 2013 at 11:12 PM 0
Share

I read that Unity Accelerometer Input also reads data from the Gyroscope on the device; Citation Needed.

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

16 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

Related Questions

Rotate object with accelerometer? 0 Answers

Rotate object to match phone's orientation 1 Answer

Rotating object based on USB Tilt Sensor 0 Answers

Rotate object with rigidbody and high angular drag around particular local axis 0 Answers

Getting X axis input from accelerometer when mobile device is held upright? 4 Answers


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