Added Tilt up down functionality to change lanes , and Removed swipe up down functionality.

posted in: Weekly Progress | 0

At The top of the script initialize the two variables.

public float TiltThreshold;
public float DeviceYAcceleration;

Tilt Functionality is added to the player script .

 

#if UNITY_ANDROID
HandleMobileInput();
#else
HandleKeyboardInput();
#endif
}

private void HandleTilt()
{
// handle mobile tilt
Vector3 dir = Vector3.zero;

dir.y = Input.acceleration.y;
dir.x = Input.acceleration.x ;

Debug.Log(string.Format(“DeviceYAcceleration {0}”, DeviceYAcceleration ) );
Debug.Log(string.Format(“Horizontal speed before normalizing {0}”, dir.y ) );
Debug.Log(string.Format(“Veryical speed before normalizing {0}”, dir.x) );

// tilt up down to move vertically
float diff = dir.y – DeviceYAcceleration;
if (Mathf.Abs(diff) >= TiltThreshold)
{
if (Mathf.Sign(diff) > 0)
{
MoveUP();
}
else
{
MoveDown();
}
}

// tilt left right to flip player
if (Mathf.Abs(dir.x) >= TiltThreshold)
{
_normalizedHorizontalSpeed = dir.x;
}
// handle mobile tilt
Vector3 dir = Vector3.zero;

 

}
private void HandleTouch()
{
if (Input.touchCount > 0)
{
// TODO dont fire if weapon icon tapped
FireWeapon();
}

Leave a Reply