- Home /
FPS view limited - I don't know why
After over a day of messing around, I finally got a joypad to control my Player for Android, using a RigidBody (I need it for my game). However, it limits the amount I can look up and down. The script is pieced from the stock FPS controller in the standards assets(mobile),which uses constraints for the X axis (That way you can't look up into a 360 degree turn). But when it's on my character controller (Capsule, Rigidbody with rotation constraints so it doesn't fall over), it constrains how far up or down I can look. I have no clue why. I can't seem to find the piece of code that causes that. Because of my game, I need to look 90degrees up and down. Below is the code for the FPS controller Im using.
var rotateTouchPad : Joystick;
var tiltPositiveYAxis = 0.6;
var tiltNegativeYAxis = 0.4;
var tiltXAxisMinimum = 0.1;
var rotationSpeed : Vector2 = Vector2( 50, 25 );
var thisTransform : Transform;
var cameraPivot : Transform;
function Update(){
var camRotation = Vector2.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 );
}
I use the standard Joystick script of the SA (Mobile).
Any help would be appreciated. Thank you.