I have for some time now been developing a First Person Shooter. I love playing on the Xbox 360 so naturally I wan’t to play the game using a 360 Controller.
All of the functionalities works on the PC and the 360 controller alike, except one thing; aiming.
Well it works how it is supposed to, but due to the inaccuracy of the thumb compared to the hand/arm used in conjunction with the mouse, aiming is really difficult on the controller. Using the mouse while aiming is fairly easy, but using the Xbox controller I can’t aim even if my life depended on it.
As said before I am aware of the inaccuracy using the analog sticks and I have compensated for that by lowering the sensitivity. However even with a fairly low sensitivity aiming is still pretty hard. And with the low sensitivity it takes almost 10 seconds turning 360 degrees, which is not feasible.
I booted up Halo 2 where aiming is near perfect. Halo 2 rotates the player by a linear value just as my game does. I noticed that the rotation on the Y axis was considerably quicker than the rotation on the X axis. So I though I would lower the sensitivity on the X axis, however no dice. It is almost impossible to aim using the controller.
It is not that I am not used to using a 360 controller. I have been using that thing on the Xbox 360 for many years. So inexperience/unfamiliarity using the controller is not a problem either.
I have this code here which is pretty much the standard MouseLook, but modified to take input from both the mouse and the 360 controller.
#pragma strict
@System.NonSerialized
var rotate = true;
var useMouseInput = false;
enum RotationAxes{MouseXAndY = 0, MouseX = 1, MouseY = 2}
var rotationAxes = RotationAxes.MouseXAndY;
static var sensitivity : float = 75.0;
var sensitivityYProcentage = 50; //The procentage that rotationY is less than rotationX
var minimumX = -360.0;
var maximumX = 360.0;
var minimumY = -85.0;
var maximumY = 90.0;
var rotationX : float;
var rotationY : float;
private var originalRotation : Quaternion;
function Start (){
if (rigidbody)
rigidbody.freezeRotation = true;
originalRotation = transform.localRotation;
}
function Update () {
if(Time.timeScale == 1 && rotate){
var rotX : float;
var rotY : float;
if(!useMouseInput){
rotX = Input.GetAxis("Right Horizontal") * sensitivity * Time.deltaTime;
rotY = Input.GetAxis("Right Vertical") * ((sensitivity / 100) * sensitivityYProcentage) * Time.deltaTime;
}else{
rotX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
rotY = Input.GetAxis("Mouse Y") * ((sensitivity / 100) * sensitivityYProcentage) * Time.deltaTime;
}
if(rotationAxes == RotationAxes.MouseXAndY){
rotationX += rotX;
rotationY += rotY;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
rotationY = ClampAngle (rotationY, minimumY, maximumY);
var xQuaternion : Quaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
var yQuaternion : Quaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
}else if(rotationAxes == RotationAxes.MouseX){
rotationX += rotX;
rotationX = ClampAngle(rotationX, minimumX, maximumX);
xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.localRotation = originalRotation * xQuaternion;
}else{
rotationY += rotY;
rotationY = ClampAngle(rotationY, minimumY, maximumY);
yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left);
transform.localRotation = originalRotation * yQuaternion;
}
}
}
public static function ClampAngle (angle : float,min : float,max : float){
if (angle < -360F)
angle += 360F;
if (angle > 360F)
angle -= 360F;
return Mathf.Clamp (angle, min, max);
}
Hopefully you’ll manage to get through the wall of text and hopefully answer my question.
Thank you.