blob: 4f2b9977651635eed840392bfb685c987ac66bdb (
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
|
using System;
using UnityEngine;
public class WalkAnimator : MonoBehaviour
{
private Pathfinder p;
[SerializeField]
private Transform directionalTransform;
[SerializeField]
private Transform rotationalOffsetTransform;
[SerializeField]
private Transform artTransform;
[SerializeField]
private float strideLength = 1f;
[SerializeField]
private float strideHeight = 1f;
[SerializeField]
private float sideAngles = 20f;
[SerializeField]
private float strideVariationPercentage = 0.1f;
private float step;
private Vector3 preiviousPosition;
private Vector3 direction;
private void Start()
{
strideLength = UnityEngine.Random.Range(strideLength * (1f - strideVariationPercentage), strideLength * (1f + strideVariationPercentage));
strideHeight = UnityEngine.Random.Range(strideHeight * (1f - strideVariationPercentage), strideHeight * (1f + strideVariationPercentage));
p = GetComponent<Pathfinder>();
preiviousPosition = base.transform.position;
}
private void FixedUpdate()
{
direction = base.transform.position - preiviousPosition;
preiviousPosition = base.transform.position;
if (direction.sqrMagnitude != 0f)
{
directionalTransform.rotation = Quaternion.LookRotation(direction, Vector3.up);
}
step = (step + p.speed * Time.fixedDeltaTime / strideLength) % 2f;
artTransform.localPosition = strideHeight * Vector3.up * Mathf.Abs(Mathf.Cos(step * (float)Math.PI));
artTransform.localEulerAngles = new Vector3(sideAngles * Mathf.Sin(step * (float)Math.PI), 0f, 0f);
}
}
|