- Home /
problem setting up a game pad
Hello everyone, this is my very first time trying to make a game pad work with unity 3d the script I am using here is very basic one :
#pragma strict
public enum RotationAxis
{
MouseX = 0,
MouseY = 1
}
var RotationAxisRotationXY = RotationAxis.MouseX | RotationAxis.MouseY;
var SensitivityX : float = 400f;
var MinimumX : float = -360f;
var MaximumX : float = 360f;
var RotationX : float = 0f;
var OriginalRotation : Quaternion;
var RotationY : float = 0f;
var MinimumY : float = -25f;
var MaximumY : float = 25f;
var SensitivityY : float = 400f;
var XQuaternion : Quaternion;
var YQuaternion : Quaternion;
function Start ()
{
}
function Update ()
{
if (RotationAxisRotationXY == RotationAxis.MouseX)
{
RotationX += Input.GetAxis("Mouse X") * SensitivityX * Time.deltaTime;
RotationX = ClampAngle(RotationX, MinimumX, MaximumX);
OriginalRotation = XQuaternion = Quaternion.AngleAxis(RotationX, Vector3.up);
transform.localRotation = OriginalRotation * XQuaternion;
}
if (RotationAxisRotationXY == RotationAxis.MouseY)
{
RotationY -= Input.GetAxis("Mouse Y") * SensitivityY * Time.deltaTime;
RotationY = ClampAngle(RotationY, MinimumY, MaximumY);
OriginalRotation = YQuaternion = Quaternion.AngleAxis(RotationY, Vector3.left);
transform.localRotation = OriginalRotation * YQuaternion;
}
}
static function ClampAngle(angle : float, min : float, max : float) : float
{
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp(angle,min,max);
}
The setting on input manager :
The screen shot of the problem,
as you can see, the calibration software shows that I am perfectly moving only on one axis, also, I checked the settings on the camera and fps control over and over again, the fps control is on rotate x and camera on rotate y, when I use the right analog stick, it rotates the camera correctly, when I move the character forward/backward everything is ok, but as soon as I move the character left and right the camera starts rotating up and down, I even tried the new sample asset's fps prefab and same error there. What am I doing wrong here?
and here is the controller script
#pragma strict
public var MoveSpeed : float = 50;
public var JumpSpeed : float = 55;
public var MoveDirection = Vector3.zero;
public var Gravity : float = 45;
public var Grounded : boolean = false;
private var controller : CharacterController;
function Start ()
{
controller = gameObject.GetComponent.<CharacterController>();
}
function Update ()
{
if (Grounded)
{
MoveDirection = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
MoveDirection = transform.TransformDirection(MoveDirection);
MoveDirection *= MoveSpeed;
}
if (Grounded)
{
if (Input.GetAxis("Jump"))
{
MoveDirection.y = JumpSpeed;
}
}
MoveDirection.y -= Gravity * Time.deltaTime;
var flags = controller.Move(MoveDirection * Time.deltaTime);
Grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
Your answer
Follow this Question
Related Questions
Mobile Joystick - How to increase the touch area 0 Answers
How do I properly rotate an FPS camera with a joystick? 1 Answer
Changing the size of the mobile FPS control GUI? 0 Answers
How to use a PS3 controller to control an FPS 2 Answers
android fps 0 Answers