• 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 DFiable · Aug 21, 2011 at 05:19 AM · androidrotationtouchaxis

Alternate command for rotation on Android ?

I have a first person tunnel game where the player is always in forward motion. When I play the game on the PC or the Web, I control movement by moving my mouse back and forth to rotate the camera 360 degrees around the z axis. When I play the game on the Android phone, I can only move the main player(rotate on z axis) by touching the screen of the phone.(it does this automatically, I didn't script it that way) I don't want to control the player movements by touching the screen, I want to move the phone to control the player. Can someone point me in the right direction? I don't even know where to start. Thanx

Here is my rotation script which is attached to my Main camera. I have a child object attached to the camera which is the main player object.(Sphere) When I move the mouse the sphere moves with the camera as it rotates 360 degrees. What commands do I need to add to this script to fix this problem? thanx

// Performs a mouse look.

var horizontalSpeed : float = 2.0;

var verticalSpeed : float = 2.0;

function Update () {

// Get the mouse delta. This is not in the range -1...1

var h : float = horizontalSpeed * Input.GetAxis ("Mouse X");

var v : float = verticalSpeed * Input.GetAxis ("Mouse Y");

transform.Rotate (v, 0, h); }

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 em2 · Aug 21, 2011 at 05:40 AM

If you want to move the device to contol something you will have to tap into the accelerometer. A good example is the roll-a-ball example and tilt functions. Check out the Input class and acceleration i.e. Input.acceleration. Hope this helps,

Cheers Chris

Comment
Add comment · Show 3 · 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 em2 · Aug 21, 2011 at 05:44 AM 0
Share

Have a look in the standard assets (mobile) > scripts, for an example of implementation.

avatar image DFiable · Aug 21, 2011 at 12:57 PM 0
Share

thank you.....

avatar image em2 · Aug 21, 2011 at 01:41 PM 0
Share

You're welcome. Chris

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Replace Input.GetAxis with Touch 2 Answers

Converting Android Axis to Unity Axis 0 Answers

Stopping rotation at 90° and -90°/270°. 0 Answers

Slerp Z and X axis only 1 Answer

OnPointerExit Issue w/ Radial Menu on Android 1 Answer

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