summaryrefslogtreecommitdiff
path: root/StandingDataHandler.cs
blob: 10a147336cf658358d7b4f13f4022caeddce8bd5 (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
using UnityEngine;

public class StandingDataHandler : MonoBehaviour
{
	public Rigidbody mainRig;

	public float sinceGrounded;

	public float sinceLanded;

	public bool isGrounded;

	public float distanceToGround = 1f;

	private bool hasRecievedTouchedGround;

	private MovementDataHandler moveMentData;

	private PlayerKnockback knockback;

	private WobbleShake wobbleShake;

	private void Start()
	{
		wobbleShake = GetComponentInChildren<WobbleShake>();
		knockback = GetComponent<PlayerKnockback>();
	}

	private void FixedUpdate()
	{
		sinceGrounded += Time.fixedDeltaTime;
		sinceLanded += Time.fixedDeltaTime;
		moveMentData = GetComponent<MovementDataHandler>();
		if ((double)sinceGrounded > 0.1)
		{
			isGrounded = false;
		}
	}

	private void LateUpdate()
	{
		hasRecievedTouchedGround = false;
	}

	public void TouchGround(float distance, Vector3 normal)
	{
		if (sinceGrounded > 0.5f && (bool)wobbleShake)
		{
			wobbleShake.AddShake(-Vector3.up * 5f * Mathf.Pow(sinceGrounded, 1.5f), 0.8f);
		}
		if (sinceGrounded > 0.5f)
		{
			Land(sinceGrounded);
		}
		sinceGrounded = 0f;
		isGrounded = true;
		if (distance > distanceToGround || !hasRecievedTouchedGround)
		{
			distanceToGround = distance;
		}
		hasRecievedTouchedGround = true;
		moveMentData.SetSlope(normal);
	}

	private void Land(float landForce)
	{
		sinceLanded = 0f;
	}
}