- Home /
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
         }        
     }
 }
 
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.
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
 
 
             Follow this Question
Related Questions
C# Move object by tilting on android device. 5 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                