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
0
Question by C-Blunt · Apr 26, 2013 at 06:57 PM · c#androidballtiltmaze

Ball maze android issues

Hi,

I'm making a basic ball maze for android and have been looking at the c# game example on the asset store. On pc it works fine but my android controls dont seem right...the left/right tilt seems backwrds and forwards/backwards is completely messed up resulting in the ball floating and bobbing around...

I want to be able to tilt the phone and roll the ball around the maze, any help is much appreciated!

Thanks.

using UnityEngine; using System.Collections;

 public class MarbleControl : MonoBehaviour {
 
     public float movementSpeed = 6.0f;
     
     void Update () {
         Vector3 movement = (Input.GetAxis("Horizontal") * -Vector3.left * movementSpeed) + (Input.GetAxis("Vertical") * Vector3.forward *movementSpeed);
         rigidbody.AddForce(movement, ForceMode.Force);
         
         //Android controls
 //    controller = GetComponent(CharacterController);        
         Vector3 dir = Vector3.zero;  //Android controls - accelorometer
         dir.x = -Input.acceleration.y;
         dir.z = Input.acceleration.x;
 //        dir.y = 0;
         //clamp acceleration vector to unit sphere
         if (dir.sqrMagnitude > 1)
             dir.Normalize();
         //move at meters/second instead of per frame
         dir *= Time.deltaTime;
         
         transform.Translate(dir * movementSpeed);
         //move ball
         //controller.Move (dir * movementSpeed);
     }
 
     void OnTriggerEnter  (Collider other  ) {
         if (other.tag == "Pickup")
         {
             MarbleGameManager.SP.FoundGem();
             Destroy(other.gameObject);
         }
         else
         {
             //Other collider.. See other.tag and other.name
         }        
     }
 }
 
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 parthdarji · May 01, 2013 at 06:55 AM

I'm not at my workspace right now, but try using gyroscope instead of accelerometer. It might just work. Revert back if it works. I'm on a similar project now and need reviews on the same.

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 C-Blunt · May 05, 2013 at 06:33 PM 0
Share

I didn't think the majority of phones/tablets have gyroscopes now, that they opt for accelerometers ins$$anonymous$$d? Or would the function work anyway, do you have any code working with the gyroscope? On a side note, if i fix the Y position of the ball's rigidbody it seems to work ok, but I need the ball moving along all 3 axis to go up/down ramps and such.

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

C# Move object by tilting on android device. 5 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

C# Tilting object with acceleration on andoid 0 Answers

Add tilt function to rotate a ball android device 0 Answers


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