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
1
Question by Bisonator · Mar 22, 2013 at 06:12 PM · androidinputaccelerometertiltperspective

Android tilt controls - taking player direction into consideration

Hi,

I'm having an issue with my game with the tilt controls. I've got the tilt controls working initially but when the player turns 90 or -90 degrees (I have made a game similar to temple run with the movement, the player is always running and a screen swipe will rotate the player + or - 90 degrees), the tilt controls continue to control the same way, so the player will just run faster or slower rather than left or right. I understand why this happens - the code just takes into consideration one axis' tilt and controls the player in the same way. I'm just really unsure how to change this for what I need.

How can I change this so that the tilt controls will affect the way the player is facing rather than generally? I feel this may be something more obvious but I've been thinking a lot and have done lots of research to no avail.

Here is my code segment for the tilt movement at the moment (javascript), just very basic:

 direction.x = Input.acceleration.x * moveSpeed;

 if (direction.sqrMagnitude > 1)
 direction.Normalize();
  
 // Make it move 10 meters per second
 direction *= Time.deltaTime;
  
 // Move object without transform to take boundaries into consideration
 controller.Move (dir * speed); 


Any help with this would be greatly appreciated. Thanks.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by CryEngineer · May 18, 2013 at 10:02 AM

I beleive you need to change last line to this:

 controller.Move (direction * speed);







add one line of code to rotate your controller:

 direction = transform.TransformDirection(direction);


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 eciosf · Aug 08, 2013 at 07:32 PM

In Unity 4.1 is not working. Any solution? When I compile in 3.5 has no problems, but I made a stupid opening my project in Unity 4.1 and I have to finish the game on it. Someone has the same difficulty?

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 sammo · Aug 09, 2013 at 09:24 AM 0
Share

Please don't post new questions as answers, if you need help consider starting your own question, thanks

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

13 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

Related Questions

How to get a force from acceleromoters instead of angle? 0 Answers

Accelerometer question 1 Answer

Unity3D cross-platform input wireless 1 Answer

Tilt movement with Unity Android 1 Answer

Hi .... i made a pc game controls work fine....how do i use accelerometer for android...for ex if i wanna move right i tilt right...etc 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