I am working on a ball rolling platformer game.
The game plays well (I think) with the WASD control scheme I have set up. I wish to make it a possibility to use the gyroscope on an android phone to play the game but I have a few issues.
- It seems almost unresponsive, but at the same time, it seems almost to sensitive.
- It’s near impossible to play - maybe it’s a lack of practice, but it’s absurdly difficult.
Things I’ve tried: making the slowing down of the ball use a higher modifier for the force applied then the speeding up of the ball, adjusting the the value I’m multiplying by using in relation to gyroscope.attitude at the beginning (using as a home base - if I relaunch the scene it doesn’t seem to accelerate at all after using this method) .
The apk asks for internet access because it phones home for hiscore management, aside from that it uses only the gyroscope and only unity functions.
A link to download the apk
My code:
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow) || Input.gyro.attitude.y > (defaultValue.y + reqOffset))
{
#if UNITY_ANDROID
float mobileMod = 1;
if (rigidbody.velocity.z > 0)
{
mobileMod = 0.7f * Mathf.Abs(Input.gyro.attitude.z);
}
else if (rigidbody.velocity.z < 0)
{
mobileMod = 1.0f * Mathf.Abs(Input.gyro.attitude.z);
}
#else
float mobileMod = 1f;
#endif
//Forward
rigidbody.AddForce(Forward * MoveModifier * mobileMod);
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow) || Input.gyro.attitude.x > (defaultValue.x + reqOffset))
{
#if UNITY_ANDROID
float mobileMod = 1;
if (rigidbody.velocity.x < 0)
{
mobileMod = 0.7f * Mathf.Abs(Input.gyro.attitude.x);
}
else if (rigidbody.velocity.x > 0)
{
mobileMod = 1.0f * Mathf.Abs(Input.gyro.attitude.x);
}
#else
float mobileMod = 1f;
#endif
//Right
rigidbody.AddForce(Right * MoveModifier * mobileMod);
}
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow) || Input.gyro.attitude.y < (defaultValue.y - reqOffset))
{
#if UNITY_ANDROID
float mobileMod = 1;
if (rigidbody.velocity.z < 0)
{
mobileMod = 0.7f * Mathf.Abs(Input.gyro.attitude.z);
}
else if (rigidbody.velocity.z > 0)
{
mobileMod = 1.0f * Mathf.Abs(Input.gyro.attitude.z);
}
#else
float mobileMod = 1f;
#endif
//Backwards
rigidbody.AddForce(Backwards * MoveModifier * mobileMod);
}
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow) || Input.gyro.attitude.x < (defaultValue.x - reqOffset))
{
#if UNITY_ANDROID
float mobileMod = 1;
if (rigidbody.velocity.x > 0)
{
mobileMod = 0.7f * Mathf.Abs(Input.gyro.attitude.x);
}
else if (rigidbody.velocity.x < 0)
{
mobileMod = 1.0f * Mathf.Abs(Input.gyro.attitude.x);
}
#else
float mobileMod = 1f;
#endif
//Left
rigidbody.AddForce(Left * MoveModifier * mobileMod);
}