- Home /
First Person Control - Tilt landscape
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 );
}
Answer by amit-chai · Aug 30, 2014 at 08:32 AM
Well Im kinda answer it myself. i've deleted all the camera script and used a simple 2 lines instead.
static var yStart : float; static var xStart : float; function Start()
{ ... yStart = Input.acceleration.y; xStart = Input.acceleration.x; ... }
cameraPivot.Rotate((Input.acceleration.y-yStart)*2, 0,0);
thisTransform.Rotate(0, (Input.acceleration.x - xStart)*5,0);
Pretty simple and working.
Your answer
![](https://koobas.hobune.stream/wayback/20220613161819im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Standard Assets (Mobile) Control Setups for game 0 Answers
If (increasing/decreasing)? check if something is increasing or decreasing 1 Answer
how to make a character lean over or back when looking up or down 2 Answers
Gun tilting in the direction you look towards 1 Answer
Too much FPS, is there a cutoff limit? 2 Answers