using UnityEngine;

public class JointController : MonoBehaviour {
    private ConfigurableJoint joint;
    private float _targetRotation = 0;
    public float RotationSpeed = 50;
    public float axisDirection = -1;

    public void Awake() {
        joint = GetComponent<ConfigurableJoint>();
    }

    public void UpdateTargetRotation(float axis) {
        _targetRotation += ((axis * axisDirection) * Time.deltaTime) * RotationSpeed;
        _targetRotation = Mathf.Clamp(_targetRotation, joint.lowAngularXLimit.limit, joint.highAngularXLimit.limit);
        joint.targetRotation = Quaternion.Euler(_targetRotation,0,0);
    }

    public void UpdateReset() {
        _targetRotation *= 0.05f;
        joint.targetRotation = Quaternion.Euler(_targetRotation, 0, 0);
    }
}