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
2
Question by TriplePAF · Jan 07, 2010 at 05:50 PM · iphonecarsteering

Accelerometer car steering and screen tilt control function

Hello,

I'm searching for a more convenient way to handle the steering control and horizon screen tilt.

At the moment I'm using this function as the base for my car steering:

public static float RotationYXAngle180Degree(Vector3 currentAcc) { float rotationAngle = Mathf.Rad2Deg * Mathf.Atan2(currentAcc.y, currentAcc.x);

 return rotationAngle;

}

For the screen horizon tilt I'm using as the base this function:

public static float RotationYXAngle360Degree(Vector3 currentAcc) { float rotationAngle = Mathf.Rad2Deg * Mathf.Atan2(currentAcc.y, currentAcc.x);

 if (rotationAngle < 0f)
     rotationAngle = rotationAngle + 360.0f;

 return rotationAngle;

}

The Vectors are calibrated with an 4x4 Matrix. Here arises already a part of my problem. If I play the game lying on my back then the screen is tilt 180 degree in the wrong direction and the car will steer the wrong way. I tried before to use only the accelerometers Y axis, It just didn't respond well.

A new solution or direction to my problem is greatly welcome ;-).

Peter.

Comment
Add comment · Show 3
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 TriplePAF · Jan 09, 2010 at 12:19 AM 0
Share

I found my own answer ;-) I have changed the the following line of code in both functions: float rotationAngle = $$anonymous$$athf.Rad2Deg $$anonymous$$athf.Atan2(currentAcc.y, currentAcc.x); to: float rotationAngle = $$anonymous$$athf.Rad2Deg $$anonymous$$athf.Atan2(currentAcc.y, $$anonymous$$athf.Abs(currentAcc.x)); The $$anonymous$$athf.Abs function makes the $$anonymous$$atrix unnecessary.

avatar image Rob Cowell · Feb 04, 2010 at 05:37 PM 0
Share

Perhaps put it as an answer and mark it as accepted, rather than a comment. It'll help others find the solution easier when searching ;-)

avatar image wana7262 · Mar 11, 2013 at 03:38 PM 0
Share

can u post the complete script?

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by morothar · Feb 08, 2010 at 01:48 PM

Since this question still at the top o the unanswered questions I hereby answer it... Hopefully it will be marked as answered soon....

I found my own answer ;-) I have changed the the following line of code in both functions: float rotationAngle = Mathf.Rad2Deg Mathf.Atan2(currentAcc.y, currentAcc.x); to: float rotationAngle = Mathf.Rad2Deg Mathf.Atan2(currentAcc.y, Mathf.Abs(currentAcc.x)); The Mathf.Abs function makes the Matrix unnecessary. TriplePAF Jan 9 at 0:19

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
avatar image
0

Answer by CallToAdventure · Nov 04, 2011 at 08:38 PM

Changed this line in both functions:

 float rotationAngle = Mathf.Rad2Deg * Mathf.Atan2(currentAcc.y, currentAcc.x);

with

  float rotationAngle = Mathf.Rad2Deg * Mathf.Atan2(currentAcc.y, Mathf.Abs(currentAcc.x)); 
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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Car Movment script not fully working 0 Answers

CAR ROTATING HELP 2 Answers

Reduce steerangle at high speeds 1 Answer

hands rotating with steering wheel 1 Answer

UnitySteer, steering script for Unity3D 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