blob: 4da2d388f98cf9108355036d28cf1c12b776dba2 (
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
|
using UnityEngine;
public class WobbleShake : MonoBehaviour
{
public Vector3 velocity = Vector3.zero;
public float friction = 0.9f;
public float movementMultiplier = 10f;
private Camera mainCam;
private void Start()
{
mainCam = base.transform.root.GetComponentInChildren<Camera>();
}
private void FixedUpdate()
{
Vector3 forward = Vector3.forward;
Vector3 vector = Vector3.Cross(base.transform.forward, forward).normalized * Vector3.Angle(base.transform.forward, forward);
forward = Vector3.up;
Vector3 vector2 = Vector3.Cross(base.transform.up, forward).normalized * Vector3.Angle(base.transform.up, forward);
velocity += (vector + vector2) * movementMultiplier;
velocity *= friction;
base.transform.Rotate(velocity, Space.World);
friction = Mathf.Lerp(friction, 0.7f, Time.fixedDeltaTime * 1f);
}
public void AddShake(Vector3 shake, float newFriction)
{
Vector3 vector = new Vector3(0f - shake.y, shake.x, shake.z);
if (Mathf.Abs(newFriction - 0.7f) > Mathf.Abs(friction - 0.7f))
{
friction = newFriction;
}
velocity += vector;
}
public void AddShakeWorld(Vector3 shake, float newFriction)
{
if ((bool)mainCam)
{
shake = mainCam.transform.TransformDirection(shake);
Vector3 vector = new Vector3(0f - Mathf.Abs(shake.z + shake.y), 0f - shake.x, 0f);
friction = newFriction;
velocity += vector;
}
}
}
|