summaryrefslogtreecommitdiff
path: root/ADS.cs
blob: d20136e2030b753d123a8583cad398806a6892d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections;
using UnityEngine;

public class ADS : MonoBehaviour
{
	public Vector3 recoilMovement;

	public Vector3 randomRecoilMovement;

	public AnimationCurve curve;

	public float animationSpeed = 1f;

	private Vector3 startPosition;

	private void Start()
	{
		startPosition = base.transform.localPosition;
	}

	private void Update()
	{
	}

	public void PlayRecoilAnimation()
	{
		StartCoroutine(ApplyRecoil());
	}

	private IEnumerator ApplyRecoil()
	{
		float counter = 0f;
		float lastValue = curve.Evaluate(0f);
		float animtionTime = curve.keys[curve.length - 1].time;
		Vector3 v = recoilMovement + new Vector3(Random.Range(0f - randomRecoilMovement.x, randomRecoilMovement.x), Random.Range(0f - randomRecoilMovement.y, randomRecoilMovement.y), Random.Range(0f - randomRecoilMovement.z, randomRecoilMovement.z));
		while (counter < animtionTime)
		{
			counter += Time.deltaTime * animationSpeed;
			if (counter > animtionTime)
			{
				counter = animtionTime;
			}
			float deltaForce = curve.Evaluate(counter) - lastValue;
			lastValue = curve.Evaluate(counter);
			base.transform.localPosition += deltaForce * v * 0.001f;
			yield return null;
		}
	}
}