- Home /
Rotating menu with 360 controller.
Hey. I'm trying to tweak my game to use controller input instead of mouse and keyboard. When I click an arrow in the menu scene it rotates 90 degrees in the arrows direction. I want it so that when the player pulls the trigger the menu rotates 90 degrees depending on the trigger pulled. For some reason it reads the input but makes the makes the menu spin rapidly for no reason.
void Update() {
//Debug 360 controller triggers
float rightTriggerPullAmount = Input.GetAxis ("Fire1");
float leftTriggerPullAmount = Input.GetAxis ("Fire2");
Debug.Log (leftTriggerPullAmount.ToString ());
Debug.Log (rightTriggerPullAmount.ToString ());
if (rightTriggerPullAmount == 1.0f)
{
float currentAngle = Camera.main.transform.rotation.eulerAngles.y;
if(Mathf.Abs(totalRotation) < Mathf.Abs(rotateDegreesAmount))
{
float rotateAmount = Time.deltaTime * degreesPerSecond;
if(totalRotation + rotateAmount > 90){
rotateAmount = 90-totalRotation;
}
Camera.main.transform.rotation = Quaternion.AngleAxis(currentAngle + rotateAmount, Vector3.up);
totalRotation += rotateAmount;
Debug.Log("Rotation Amount: " + rotateAmount.ToString());
}
//Debug.Log(totalRotation);
}
if (isLeftArrowClicked )
{
float currentAngle = Camera.main.transform.rotation.eulerAngles.y;
if(Mathf.Abs(totalRotation) < Mathf.Abs(rotateDegreesAmount))
{
float rotateAmount = Time.deltaTime * degreesPerSecond;
if(totalRotation + rotateAmount > 90){
rotateAmount = 90-totalRotation;
}
Camera.main.transform.rotation = Quaternion.AngleAxis(currentAngle - rotateAmount, Vector3.up);
totalRotation += rotateAmount;
}
Debug.Log("Total rotation: " + totalRotation.ToString());
isRightArrowClicked = false;
}
if (isRightArrowClicked)
{
float currentAngle = Camera.main.transform.rotation.eulerAngles.y;
if(Mathf.Abs(totalRotation) < Mathf.Abs(rotateDegreesAmount))
{
float rotateAmount = Time.deltaTime * degreesPerSecond;
if(totalRotation + rotateAmount > 90){
rotateAmount = 90-totalRotation;
}
Camera.main.transform.rotation = Quaternion.AngleAxis(currentAngle + rotateAmount, Vector3.up);
totalRotation += rotateAmount;
Debug.Log("Rotation Amount: " + rotateAmount.ToString());
}
//Debug.Log(totalRotation);
isLeftArrowClicked = false;
//Debug.Log(camYRot.ToString());
}
}
At a glance it seems you only use the full-on condition of the trigger. Why not make it more procedural by integrating the value in to your calculations rather than treating it like a switch?
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Input Help! 1 Answer
Implementing Deceleration on a car? 0 Answers
Gameplay issues when playing in Editor. Works fine in build. 0 Answers
Turning to face movement direction 0 Answers