Right Stick Aiming Problem (Dual Stick Shooter)

Hello, I’m currently building a dual stick shooter using a PS4 controller and after getting the right analogue stick to work properly (“3rd-axis” and “6th-axis” weirdly if anyone wants to know), I’m now having difficulties with the movement of my turret.

When the input on the y axis is positive, the aiming is fine, however when I flip the x rotation when the input is negative, it does it constantly. I’m guessing I should run some sort of check with the current axis to stop it from doing this, but I can’t seem to figure it out. Here’s the script anyway:

using UnityEngine;
using System.Collections;

public class PlayerAiming : MonoBehaviour
{
    // Update is called once per frame
    void Update ()
    {
        // We are going to read the input every frame
        Vector3 vNewInput = new Vector3(Input.GetAxis("RightStickX"), Input.GetAxis("RightStickY"), 0.0f);
        // Only do work if meaningful
        if(vNewInput.sqrMagnitude < 0.1f)
        {
            return;
        }

        // Set our rotation to represent the input
        vNewInput.Normalize();
        float fHeading = Vector3.Dot(Vector3.right, vNewInput);
        Vector3 vNewRotation = transform.rotation.eulerAngles;
        vNewRotation.z = fHeading * 90.0f;

        // Adjust our rotation if we're on the bottom half of the input circle
        if(vNewInput.y > 0.0f)
        {	
			Debug.Log(new Vector2(Input.GetAxis("RightStickX"), Input.GetAxis("RightStickY"))); //report value of right thumbstick
			
            vNewRotation.x = 180.0f - vNewRotation.x;    
        }

        // Apply the transform to the object        
        transform.rotation = Quaternion.Euler(vNewRotation);
    }
}

Any Help would be appreciated thanks.

Managed to figure it out using some of the code from [this][1]
[and this][2]

[1]: Rotating an object - Unity Answers)
[2]: Add 90 Degrees to Transform.Rotation - Unity Answers
Here is the modified code if anyone is interested:

using UnityEngine;
using System.Collections;

public class PlayerAiming : MonoBehaviour
{
    // Update is called once per frame
    void Update ()
    {
        // We are going to read the input every frame
        Vector3 vNewInput = new Vector3(Input.GetAxis("RightStickX"), Input.GetAxis("RightStickY"), 0.0f);
		
        // Only do work if meaningful
        if(vNewInput.sqrMagnitude < 0.1f)
        {
            return;
        }

        // Apply the transform to the object  
		var angle = Mathf.Atan2(Input.GetAxis("RightStickX"), Input.GetAxis("RightStickY")) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.Euler(angle, 0, 0);
    }
}

I dont know how anyone hasnt thanked you yet but this is immensely helpful!

Thank you so much for this! It really helped me out a lot.