• 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.

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

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

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

Unity3D cross-platform input wireless 1 Answer

Gyroscope.userAcceleration returning zero 0 Answers

Android Tilt controls help 1 Answer

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