- Home /
How to use Android Accelerometer(Left and right tilt) to turn a sphere object and camera in that direction?
While controlling a sphere ball through accelerometer, while turning left or right I want both the object and the camera to turn towards that direction. Current State : ball moving in that direction and camera is only looking at the ball, not in the direction in which it is moving. I have been trying to look solutions to this problem for the past several days; Any help would be much appreciated. :)
Ball Controller:
 curAc = Vector3.Lerp(curAc, Input.acceleration-zeroAc, Time.deltaTime/smooth);
                 GetAxisV = Mathf.Clamp(curAc.y * sensV, -1, 1);
                 GetAxisH = Mathf.Clamp(curAc.x * sensH, -1, 1);
 
                 Vector3 movement = new Vector3 (GetAxisH, 0.0f, GetAxisV);
 
                 GetComponent<Rigidbody>().AddTorque(movement * speedAc);
Camera Controller:
 void Start()
     {
         playerOffset = transform.position - player.transform.position;
     }
 
     
     void LateUpdate()
     {
         transform.position = player.transform.position + playerOffset;
     }
Answer by Sid.10 · Dec 23, 2015 at 04:27 PM
I'm the OP, but I solved the problem, atleast to my satisfaction. Creating an empty game object and making the ball and the camera child of it worked for me. The hierarchy :
- Empty Game Object(Container)(Parent) 
- Ball(Child 1) 
- Camera(Child 2) 
Then, apply the movement controller script on that empty game object. Hope this helps to someone in the future. Cheers :)
Your answer
 
 
             Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Disable Camera Movement,Stop camera movement 0 Answers
Regarding transform.position in the roll a ball tutorial 1 Answer
Why does my app function correctly in Unity Remote but not compiled as an app? 0 Answers
Standard asset question 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                