Lerp between two angles

Hello,

I am making a hammer rotating around its X axis and its child (pivot) swinging around its Y axis. But I have 3 problems:

  1. It will not lerp within the given time from -angleMax to angleMax.

  2. it will not rotate based on timeScale multiplier; it still rotates until it reaches angleMax.

  3. The progress value should describe the progress from angleMax (0) to -angleMax (1) and vice Versa. But the value is too large, so I divided with 75.

      private var pivot : Transform;
    

    public var rotSpeed : float = 18f;
    public var angleMax : float = 75f;
    public var lerpTime : float = 8f;
    public var progress : float;
    public var currentX : float;
    public var isReversing : boolean;

    function Start () {
    pivot = transform.GetChild(0);
    pivot.rotation.eulerAngles.x = angleMax;

    currentX = pivot.rotation.eulerAngles.x;
    

    }

    function Update () {
    transform.RotateAround(transform.position, Vector3.up, rotSpeed * Time.deltaTime * Time.timeScale);

    if(progress < 1f){
    	progress += (Time.deltaTime / lerpTime) * Time.timeScale;
    } else {
    	progress = 0f;
    	isReversing = !isReversing;
    }
    
    if(!isReversing){
    	currentX = Mathf.Lerp(currentX, -angleMax, progress/75);
    } else {
    	currentX = Mathf.Lerp(currentX, angleMax, progress/75);
    }
    
    pivot.localRotation.eulerAngles.x = currentX;
    

    }

Might be because you’re lerping from currentX (instead of -angleMax) to angleMax.
Try to see if this fixes it:

currentX = Mathf.Lerp(-angleMax, angleMax, progress);