summaryrefslogtreecommitdiff
path: root/MovementDataHandler.cs
blob: 18d43f5cbe6f1e39e4bc880d3d9d60fb0a513318 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using UnityEngine;

public class MovementDataHandler : MonoBehaviour
{
	[HideInInspector]
	public Vector3 groundedForward;

	[HideInInspector]
	public Vector3 right;

	[HideInInspector]
	public Vector3 left;

	[HideInInspector]
	public Vector3 groundedBack;

	private Transform hip;

	private Transform torso;

	public Transform rotationTarget;

	[HideInInspector]
	public float slopeStrenght;

	public float slopeVelocityStrenght;

	[HideInInspector]
	public float sinceJump = 1f;

	[HideInInspector]
	public Vector3 groundNormal;

	private InputHandler inputHandler;

	private Transform leftKnee;

	private Transform rightKnee;

	private void Start()
	{
		inputHandler = GetComponent<InputHandler>();
		hip = GetComponentInChildren<Hip>().transform;
		torso = GetComponentInChildren<Torso>().transform;
		if (!rotationTarget)
		{
			rotationTarget = GetComponentInChildren<RotationTarget>().transform;
		}
		KneeLeft componentInChildren = GetComponentInChildren<KneeLeft>();
		if ((bool)componentInChildren)
		{
			leftKnee = componentInChildren.transform;
		}
		KneeRight componentInChildren2 = GetComponentInChildren<KneeRight>();
		if ((bool)componentInChildren2)
		{
			rightKnee = componentInChildren2.transform;
		}
	}

	private void Update()
	{
		sinceJump += Time.deltaTime;
		groundedForward = rotationTarget.forward;
		groundedForward.y = slopeStrenght * 1f;
		groundedForward = groundedForward.normalized;
		groundedBack = -groundedForward;
		right = rotationTarget.right;
		left = -rotationTarget.right;
		slopeStrenght = Mathf.Lerp(slopeStrenght, 0f, Time.deltaTime * 1f);
		Debug.DrawLine(hip.position, hip.position + groundedForward * 10f);
	}

	public void SetSlope(Vector3 normal)
	{
		groundNormal = normal;
		slopeStrenght = Vector3.Cross(rotationTarget.right, normal).y;
		Vector3 lhs = Vector3.Cross(Vector3.up, inputHandler.inputMovementDirection);
		slopeVelocityStrenght = Vector3.Cross(lhs, normal).y;
	}

	public float GetSmallestLegAngle()
	{
		float num = Vector3.Angle(leftKnee.forward, Vector3.down);
		float num2 = Vector3.Angle(rightKnee.forward, Vector3.down);
		if (num < num2)
		{
			return num;
		}
		return num2;
	}
}