Hi,
Im trying to use Unity’s First Person Control to simulate tilt view. As mentioned in the Script, i’ve Removed the “Rotate Right Pad” field from the First Person Control, and left it empty to achieve the tilt view. Well its sure tilting, but only as if i’m holding the device as portrait. How can i switch it to landscape?
Tnx!
Attached script -
…
if ( character.isGrounded )
{
var camRotation = Vector3.zero;
if ( rotateTouchPad )
camRotation = rotateTouchPad.position;
else
{
// Use tilt instead
print( iPhoneInput.acceleration );
var acceleration = Input.acceleration;
var absTiltX = Mathf.Abs( acceleration.x );
if ( acceleration.z < 0 && acceleration.x < 0 )
{
if ( absTiltX >= tiltPositiveYAxis )
camRotation.y = (absTiltX - tiltPositiveYAxis) / (1 - tiltPositiveYAxis);
else if ( absTiltX <= tiltNegativeYAxis )
camRotation.y = -( tiltNegativeYAxis - absTiltX) / tiltNegativeYAxis;
}
if ( Mathf.Abs( acceleration.y ) >= tiltXAxisMinimum )
camRotation.x = -(acceleration.y - tiltXAxisMinimum) / (1 - tiltXAxisMinimum);
}
camRotation.x *= rotationSpeed.x;
camRotation.y *= rotationSpeed.y;
camRotation *= Time.deltaTime;
// Rotate the character around world-y using x-axis of joystick
thisTransform.Rotate( 0, camRotation.x, 0, Space.World );
// Rotate only the camera with y-axis input
cameraPivot.Rotate( -camRotation.y, 0, 0 );
}