- Home /
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); }
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
Have a look in the standard assets (mobile) > scripts, for an example of implementation.
Your answer
Follow this Question
Related Questions
Replace Input.GetAxis with Touch 2 Answers
Stopping rotation at 90° and -90°/270°. 0 Answers
Converting Android Axis to Unity Axis 0 Answers
Input for Android 2 Answers