This repository was archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLivPlayerEntity.cs
167 lines (145 loc) · 8.36 KB
/
LivPlayerEntity.cs
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using UnityEngine;
namespace FPSCamera
{
public class LivPlayerEntity
{
private PluginCameraHelper pluginCameraHelper;
public Transform waist { get { return pluginCameraHelper.playerHead; } }
public Transform rightHand { get { return pluginCameraHelper.playerRightHand; } }
public Transform leftHand { get { return pluginCameraHelper.playerLeftHand; } }
public Transform head { get { return pluginCameraHelper.playerHead; } }
public Transform leftFoot { get { return pluginCameraHelper.playerLeftFoot; } }
public Transform rightFoot { get { return pluginCameraHelper.playerRightFoot; } }
public Vector3 handAverage { get { return ((rightHand.position + leftHand.position) / 2); } }
public Vector3 leftEye { get { return pluginCameraHelper.playerLeftEyePosition; } }
public Vector3 rightEye { get { return pluginCameraHelper.playerRightEyePosition; } }
// TODO: Probably better in the future to actually look into ANGULAR velocities, instead of cheaping it out like this.
public Vector3 headRRadialDelta { get; private set; } = Vector3.zero;
public Vector3 leftHandRRadialDelta { get; private set; } = Vector3.zero;
public Vector3 rightHandRRadialDelta { get; private set; } = Vector3.zero;
public TimerHelper timerHelper { get; private set; }
public LivPlayerEntity(PluginCameraHelper helper, ref TimerHelper timerHelper)
{
this.pluginCameraHelper = helper;
this.timerHelper = timerHelper;
}
private Vector3 preCalculatedAbovePlayer;
private Vector3 preCalculatedBelowPlayer;
private Vector3 preCalculatedLeftHeadDirection;
private Vector3 preCalculatedRightHeadDirection;
private Vector3 preCalculatedAboveHeadDirection;
private Vector3 preCalculatedBelowHeadDirection;
private Vector3 preCalculatedFrontDirection;
// Smooth Damp Used values, which are predetermiend with the offsets.
public Vector3 headAboveDirection { get; private set; } = Vector3.zero;
public Vector3 headBelowDirection { get; private set; } = Vector3.zero;
// The following will ALWAYS be forward relative. These are just to check where the player is currently pointing towards
// Users tend to be looking down if playinga shooter already, thus the vertical offset up..
public Vector3 headForwardRightDirection { get; private set; } = Vector3.zero;
public Vector3 headForwardLeftDirection { get; private set; } = Vector3.zero;
// Saving these for probably later, when I figure in what cases could these be useful.
public Vector3 headForwardUpDirection { get; private set; } = Vector3.zero;
public Vector3 headForwardDownDirection { get; private set; } = Vector3.zero;
public Vector3 headForwardDirection { get; private set; } = Vector3.zero;
public Vector3 headBackwardDirection { get; private set; } = Vector3.zero;
public Vector3 preCalculatedBackDirection { get; private set; } = Vector3.zero;
public Vector3 leftHandForwardDirection { get; private set; } = Vector3.zero;
public Vector3 rightHandForwardDirection { get; private set; } = Vector3.zero;
private Vector3 dampedCameraForwardVelocity = Vector3.zero;
private Vector3 dampedRightHandForwardVelocity = Vector3.zero;
private Vector3 dampedLeftHandForwardVelocity = Vector3.zero;
private Vector3 dampedForwardCamera = Vector3.zero;
private Vector3 dampedRightHand = Vector3.zero;
private Vector3 dampedLeftHand = Vector3.zero;
public void SetOffsets(float horizontalOffset, float verticalOffset, float distance)
{
preCalculatedAbovePlayer = new Vector3(0, verticalOffset, 0);
preCalculatedBelowPlayer = -preCalculatedAbovePlayer;
preCalculatedLeftHeadDirection = new Vector3(horizontalOffset, verticalOffset, distance);
preCalculatedRightHeadDirection = new Vector3(-horizontalOffset, verticalOffset, distance);
preCalculatedAboveHeadDirection = new Vector3(0, verticalOffset, distance);
preCalculatedBelowHeadDirection = new Vector3(0, -verticalOffset, distance);
preCalculatedFrontDirection = new Vector3(0, 0, distance);
preCalculatedBackDirection = new Vector3(0, 0, -0.2f);
}
public void CalculateInfo()
{
// Relative Directions from the current position of the head, but not including rotation.
headAboveDirection = head.position + preCalculatedAbovePlayer;
headBelowDirection = head.position + preCalculatedBelowPlayer;
// The following will ALWAYS be forward relative. These are just to check where the player is currently pointing towards
// Users tend to be looking down if playinga shooter already, thus the vertical offset up..
headForwardRightDirection = head.TransformPoint(preCalculatedLeftHeadDirection);
headForwardLeftDirection = head.TransformPoint(preCalculatedRightHeadDirection);
// Saving these for probably later, when I figure in what cases could these be useful.
headForwardUpDirection = head.TransformPoint(preCalculatedAboveHeadDirection);
headForwardDownDirection = head.TransformPoint(preCalculatedBelowHeadDirection);
headForwardDirection = head.TransformPoint(preCalculatedFrontDirection);
headBackwardDirection = head.TransformPoint(preCalculatedBackDirection);
rightHandForwardDirection = rightHand.TransformPoint(preCalculatedFrontDirection);
leftHandForwardDirection = leftHand.TransformPoint(preCalculatedFrontDirection);
// Trying to make this is as simple as possible: Check the distance between the last damped location and the current one, relative to the head rotation.
// RRadia being "Relative Radial", as thats what it... technically is. Its not TRUE radial velocity, but its the difference between the damped and the current values
headRRadialDelta = head.InverseTransformPoint(headForwardDirection) - head.InverseTransformPoint(dampedForwardCamera);
leftHandRRadialDelta = leftHand.InverseTransformPoint(rightHandForwardDirection) - leftHand.InverseTransformPoint(dampedLeftHand);
rightHandRRadialDelta = rightHand.InverseTransformPoint(leftHandForwardDirection) - rightHand.InverseTransformPoint(dampedRightHand);
dampedLeftHand = Vector3.SmoothDamp(dampedLeftHand, leftHandForwardDirection, ref dampedLeftHandForwardVelocity, 0.3f);
dampedRightHand = Vector3.SmoothDamp(dampedRightHand, rightHandForwardDirection, ref dampedRightHandForwardVelocity, 0.3f);
dampedForwardCamera = Vector3.SmoothDamp(dampedForwardCamera, headForwardDirection, ref dampedCameraForwardVelocity, 0.3f);
}
}
public class TimerHelper
{
public float globalTimer { get; private set; }
public float controllerTimer { get; private set; }
public float cameraTimer { get; private set; }
public float cameraActionTimer { get; private set; }
public float removeAvatarTimer { get; private set; }
public float cameraGunTimer { get; private set; }
public TimerHelper()
{
globalTimer = 0;
cameraTimer = 0;
cameraActionTimer = 0;
removeAvatarTimer = 0;
cameraGunTimer = 0;
}
public void AddTime(float delta)
{
globalTimer += delta;
controllerTimer += delta;
cameraActionTimer += delta;
cameraTimer += delta;
removeAvatarTimer += delta;
cameraGunTimer += delta;
}
public void ResetGlobalCameraTimer()
{
globalTimer = 0;
}
public void ResetCameraTimer()
{
cameraTimer = 0;
}
public void SetGlobalTimer(float timer)
{
globalTimer = timer;
}
public void ResetCameraActionTimer()
{
cameraActionTimer = 0;
}
public void ResetControllerTimer()
{
controllerTimer = 0;
}
public void ResetRemoveAvatarTimer()
{
removeAvatarTimer = 0;
}
public void ResetCameraGunTimer()
{
cameraGunTimer = 0;
}
}
}