• 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 /
  • Help Room /
avatar image
0
Question by Mosy · Aug 27, 2015 at 10:59 PM · accelerometerrotation axis

Accelerometer & Rotation

Ok so I'm trying to make a game which uses the accelerometer and rotation to control a game object. I am having a problem with the rotation though. I'm using C# for all of my coding. First I started out by putting the value from Input.acceleration into a Vector3:

 Vector3 thisRotation = new Vector3 (Input.acceleration.y * 100, 0, Input.acceleration.x * 100);

I'm attempting to keep the object from rotating in the Y axis, and my current method is actually working quite well in that regard, and I am also trying to control the object in a top down landscape view. When I put Input.acceration.x into the x, and y into the z it actually showed me that the values were not what I was expecting. That is the reason why I set up that line of code the way I did.

Inorder to get my game object to rotate I am using this line of code with thisGameObject representing the game object I want to apply the rotations to.

 thisGameObject.transform.rotation = Quaternion.Slerp(thisGameObject.transform.rotation, Quaternion.Euler(thisGameObject.transform.rotation.x + thisRotation.x,
                                                                  thisGameObject.transform.rotation.y + thisRotation.y, thisGameObject.transform.rotation.z + thisRotation.z), Time.fixedDeltaTime);

My problem is that the game object is rotating in the opposite direction in the X and Z axes. I have tried to change the application of the 100 modifier in the input section to a -100, and I tried multiplying the rotations by -1 in the rotating line of code. Regardless of what I do though it seems to be rotating opposite of what is the desired effect. For reference my game is locked in a right side up landscape view. Also when I tried to use the Rotate function the game object would just continue to rotate. These lines of code are happening inside of the FixedUpdate function.

Comment
Add comment · Show 1
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 Mosy · Aug 28, 2015 at 07:21 PM 0
Share

Still looking for help on this issue.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Martians135 · Jun 16, 2017 at 05:09 AM

May be this asset can helps: You can use this asset to Do the rotation. You can use the accelerometer like a gyroscope , this works on all phones, because all devices have accelerometer. And works on all axes. Here this asset:

https://www.assetstore.unity3d.com/en/#!/content/87609

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

27 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

Related Questions

Camera rotation in maze game depending of accelerometer 0 Answers

Acceleration and accelerometer calibration 0 Answers

Does Input.acceleration use gyroscope? 2 Answers

Assign an object rotation along a single axis from other object's rotation. 0 Answers

How can I fix rotation of Z axis to 0? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges