﻿using UnityEngine;

public class VisualRecoil : MonoBehaviour {
    [SerializeField]
    float moveBackSpeed;

    [SerializeField]
    float moveBackDistance;

    private Vector3 initialLocalPosition;

    void Start() {
        initialLocalPosition = transform.localPosition;
    }

    void Update() {
        if (Input.GetMouseButtonDown(0)) {
            Vector3 localForward = transform.worldToLocalMatrix.MultiplyVector(transform.forward);
            transform.localPosition -= localForward * moveBackDistance;
        }
        transform.localPosition = Vector3.MoveTowards(transform.localPosition, initialLocalPosition, moveBackSpeed * Time.deltaTime);
    }
}
