summaryrefslogtreecommitdiff
path: root/GameCode/RightLeftMirrorSpring.cs
blob: b13966c8520aba84b56e133e735577a44358bc79 (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
using UnityEngine;

public class RightLeftMirrorSpring : MonoBehaviour
{
	public Vector3 leftPos;

	private Vector3 rightPos;

	public float leftRot;

	public float rightRot;

	private Vector3 posVel;

	private float rotVel;

	public float drag = 25f;

	public float spring = 25f;

	private Holdable holdable;

	private float currentRot;

	private void Start()
	{
		currentRot = base.transform.localEulerAngles.z;
		holdable = base.transform.root.GetComponent<Holdable>();
		rightPos = base.transform.localPosition;
	}

	private void Update()
	{
		if ((bool)holdable && (bool)holdable.holder)
		{
			bool num = base.transform.root.position.x - 0.1f < holdable.holder.transform.position.x;
			Vector3 vector = (num ? leftPos : rightPos);
			float num2 = (num ? leftRot : rightRot);
			posVel = FRILerp.Lerp(posVel, (vector - base.transform.localPosition) * spring, drag);
			rotVel = FRILerp.Lerp(rotVel, (num2 - currentRot) * spring, drag);
			currentRot += rotVel * TimeHandler.deltaTime;
			base.transform.localPosition += posVel * TimeHandler.deltaTime;
			base.transform.localEulerAngles = new Vector3(0f, 0f, currentRot);
		}
	}
}