Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making a game where you control a platform with balls falling ontop of it, and you have to balance the balls and prevent them from falling off. I'm currently using a mouse to control it with this code:

transform.rotation.eulerAngles.z+=Input.GetAxisRaw("Mouse X");
transform.rotation.eulerAngles.x+=Input.GetAxisRaw("Mouse Y");

I'm trying to make this an Android app, and want to use motion controls so I can tilt the device, as if it were the platform. I figured I would use the accelerometer for this, but I'm not sure. Any ideas on how to do this?

Thanks, -Chris

share|improve this question
    
Unity wraps the accelerometer. Plenty of links and examples –  Sergio 2 days ago
    
Pedantically speaking, rotation of a device is detected using a gyroscope, not an accelerometer (though they are often combined into a single chip). The former senses angular acceleration, while the latter detects linear acceleration. –  bcrist 2 days ago
    
@Sergio I've tried to use the documentation, but it hasn't worked for me. Can you give some sample code? –  Chris yesterday
    
@bcrist Most devices don't have a gyro, apparently. My Galaxy S3 apparently does, and some code I wrote with the gyro didn't work. Can you give some code? –  Chris yesterday
    
@Chris I've never done any mobile development with Unity; my experience with accel/gyros comes from embedded (microcontroller) programming. If you don't have a gyro, it can be faked by low-pass filtering the accelerometer output, on the assumption that most of the time, gravity is the only significant force detected. Even with a gyro, you usually want to combine it with this technique - the gyro is more accurate, but it only detects relative rotation, so it will drift without some absolute reference. –  bcrist yesterday
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.