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

public class DoggoMovement : MonoBehaviour
{
	public float drag = 0.1f;

	private CollisionChecker[] checkers;

	private Rigidbody rig;

	private Rigidbody[] rigs;

	private MovementHandler move;

	private void Start()
	{
		move = base.transform.root.GetComponent<MovementHandler>();
		rigs = base.transform.root.GetComponentsInChildren<Rigidbody>();
		checkers = base.transform.root.GetComponentsInChildren<CollisionChecker>();
		rig = GetComponent<Rigidbody>();
	}

	private void FixedUpdate()
	{
		float num = 1f;
		num = 0f;
		for (int i = 0; i < checkers.Length; i++)
		{
			if (checkers[i].sinceGrounded < 0.3f)
			{
				num += 1f / (float)checkers.Length;
			}
		}
		move.multiplier = num;
		Rigidbody[] array = rigs;
		foreach (Rigidbody rigidbody in array)
		{
			rigidbody.velocity *= 1f - drag * num;
			rigidbody.angularVelocity *= 1f - drag * num;
		}
		rig.AddTorque(Vector3.Angle(base.transform.up, Vector3.up) * Vector3.Cross(base.transform.up, Vector3.up) * 50f * num, ForceMode.Acceleration);
	}
}