com.steelboxgames.firstpersonmovement 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Runtime/MovementHelper.cs +99 -0
- package/Runtime/MovementHelper.cs.meta +3 -0
- package/Runtime/PlayerController.prefab +452 -0
- package/Runtime/PlayerController.prefab.meta +7 -0
- package/Runtime/PlayerMovement.cs +141 -0
- package/Runtime/PlayerMovement.cs.meta +3 -0
- package/Runtime.meta +8 -0
- package/package.json +20 -0
- package/package.json.meta +7 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
using UnityEngine;
|
2
|
+
|
3
|
+
namespace Game.FirstPersonMovement
|
4
|
+
{
|
5
|
+
public static class MovementHelper
|
6
|
+
{
|
7
|
+
/// <summary>
|
8
|
+
/// Accelerate a vector in a direction given speed and acceleration
|
9
|
+
/// </summary>
|
10
|
+
public static Vector3 Accelerate(Vector3 velocity, Vector3 wishDir, float wishSpeed, float accel)
|
11
|
+
{
|
12
|
+
float addSpeed, accelSpeed, currentSpeed;
|
13
|
+
|
14
|
+
currentSpeed = Vector3.Dot(velocity, wishDir);
|
15
|
+
addSpeed = wishSpeed - currentSpeed;
|
16
|
+
|
17
|
+
if (addSpeed <= 0)
|
18
|
+
return velocity;
|
19
|
+
|
20
|
+
accelSpeed = accel * Time.unscaledDeltaTime * wishSpeed;
|
21
|
+
|
22
|
+
if (accelSpeed > addSpeed)
|
23
|
+
accelSpeed = addSpeed;
|
24
|
+
|
25
|
+
velocity.x += accelSpeed * wishDir.x;
|
26
|
+
velocity.z += accelSpeed * wishDir.z;
|
27
|
+
|
28
|
+
return velocity;
|
29
|
+
}
|
30
|
+
|
31
|
+
/// <summary>
|
32
|
+
/// Applies friction to a velocity vector
|
33
|
+
/// </summary>
|
34
|
+
public static Vector3 ApplyFriction(Vector3 velocity, float friction, float runDeacceleration, float t)
|
35
|
+
{
|
36
|
+
Vector3 vec = velocity;
|
37
|
+
float speed;
|
38
|
+
float newspeed;
|
39
|
+
float control;
|
40
|
+
float drop;
|
41
|
+
|
42
|
+
vec.y = 0.0f;
|
43
|
+
speed = vec.magnitude;
|
44
|
+
drop = 0.0f;
|
45
|
+
|
46
|
+
control = speed < runDeacceleration ? runDeacceleration : speed;
|
47
|
+
drop = control * friction * Time.unscaledDeltaTime * t;
|
48
|
+
|
49
|
+
newspeed = speed - drop;
|
50
|
+
if(newspeed < 0)
|
51
|
+
newspeed = 0;
|
52
|
+
if(speed > 0)
|
53
|
+
newspeed /= speed;
|
54
|
+
|
55
|
+
velocity.x *= newspeed;
|
56
|
+
velocity.z *= newspeed;
|
57
|
+
|
58
|
+
return velocity;
|
59
|
+
}
|
60
|
+
|
61
|
+
/// <summary>
|
62
|
+
/// Applies air control to a velocity vector
|
63
|
+
/// </summary>
|
64
|
+
public static Vector3 AirControl(Vector3 velocity, Vector3 wishDir, float airControl, float wishSpeed) {
|
65
|
+
float zspeed;
|
66
|
+
float speed;
|
67
|
+
float dot;
|
68
|
+
float k;
|
69
|
+
|
70
|
+
if(Mathf.Abs(Input.GetAxis("Vertical")) < 0.001 || Mathf.Abs(wishSpeed) < 0.001)
|
71
|
+
return velocity;
|
72
|
+
|
73
|
+
zspeed = velocity.y;
|
74
|
+
velocity.y = 0;
|
75
|
+
|
76
|
+
speed = velocity.magnitude;
|
77
|
+
velocity.Normalize();
|
78
|
+
|
79
|
+
dot = Vector3.Dot(velocity, wishDir);
|
80
|
+
k = 32;
|
81
|
+
k *= airControl * dot * dot * Time.unscaledDeltaTime;
|
82
|
+
|
83
|
+
if (dot > 0)
|
84
|
+
{
|
85
|
+
velocity.x = velocity.x * speed + wishDir.x * k;
|
86
|
+
velocity.y = velocity.y * speed + wishDir.y * k;
|
87
|
+
velocity.z = velocity.z * speed + wishDir.z * k;
|
88
|
+
|
89
|
+
velocity = velocity.normalized;
|
90
|
+
}
|
91
|
+
|
92
|
+
velocity.x *= speed;
|
93
|
+
velocity.y = zspeed;
|
94
|
+
velocity.z *= speed;
|
95
|
+
|
96
|
+
return velocity;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
@@ -0,0 +1,452 @@
|
|
1
|
+
%YAML 1.1
|
2
|
+
%TAG !u! tag:unity3d.com,2011:
|
3
|
+
--- !u!1 &1169133041383888513
|
4
|
+
GameObject:
|
5
|
+
m_ObjectHideFlags: 0
|
6
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
7
|
+
m_PrefabInstance: {fileID: 0}
|
8
|
+
m_PrefabAsset: {fileID: 0}
|
9
|
+
serializedVersion: 6
|
10
|
+
m_Component:
|
11
|
+
- component: {fileID: 379312770605712307}
|
12
|
+
- component: {fileID: 6493628548323322590}
|
13
|
+
- component: {fileID: 1713753630477276169}
|
14
|
+
- component: {fileID: 2393812327530706906}
|
15
|
+
m_Layer: 0
|
16
|
+
m_Name: PlayerController
|
17
|
+
m_TagString: Untagged
|
18
|
+
m_Icon: {fileID: 0}
|
19
|
+
m_NavMeshLayer: 0
|
20
|
+
m_StaticEditorFlags: 0
|
21
|
+
m_IsActive: 1
|
22
|
+
--- !u!4 &379312770605712307
|
23
|
+
Transform:
|
24
|
+
m_ObjectHideFlags: 0
|
25
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
26
|
+
m_PrefabInstance: {fileID: 0}
|
27
|
+
m_PrefabAsset: {fileID: 0}
|
28
|
+
m_GameObject: {fileID: 1169133041383888513}
|
29
|
+
serializedVersion: 2
|
30
|
+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
31
|
+
m_LocalPosition: {x: 0, y: 0, z: 0}
|
32
|
+
m_LocalScale: {x: 1, y: 1, z: 1}
|
33
|
+
m_ConstrainProportionsScale: 0
|
34
|
+
m_Children:
|
35
|
+
- {fileID: 293513943171419127}
|
36
|
+
- {fileID: 4018879618047319413}
|
37
|
+
m_Father: {fileID: 0}
|
38
|
+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
39
|
+
--- !u!143 &6493628548323322590
|
40
|
+
CharacterController:
|
41
|
+
m_ObjectHideFlags: 0
|
42
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
43
|
+
m_PrefabInstance: {fileID: 0}
|
44
|
+
m_PrefabAsset: {fileID: 0}
|
45
|
+
m_GameObject: {fileID: 1169133041383888513}
|
46
|
+
m_Material: {fileID: 0}
|
47
|
+
m_IncludeLayers:
|
48
|
+
serializedVersion: 2
|
49
|
+
m_Bits: 0
|
50
|
+
m_ExcludeLayers:
|
51
|
+
serializedVersion: 2
|
52
|
+
m_Bits: 0
|
53
|
+
m_LayerOverridePriority: 0
|
54
|
+
m_ProvidesContacts: 0
|
55
|
+
m_Enabled: 1
|
56
|
+
serializedVersion: 3
|
57
|
+
m_Height: 2
|
58
|
+
m_Radius: 0.5
|
59
|
+
m_SlopeLimit: 45
|
60
|
+
m_StepOffset: 0.3
|
61
|
+
m_SkinWidth: 0.08
|
62
|
+
m_MinMoveDistance: 0.001
|
63
|
+
m_Center: {x: 0, y: 1, z: 0}
|
64
|
+
--- !u!114 &1713753630477276169
|
65
|
+
MonoBehaviour:
|
66
|
+
m_ObjectHideFlags: 0
|
67
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
68
|
+
m_PrefabInstance: {fileID: 0}
|
69
|
+
m_PrefabAsset: {fileID: 0}
|
70
|
+
m_GameObject: {fileID: 1169133041383888513}
|
71
|
+
m_Enabled: 1
|
72
|
+
m_EditorHideFlags: 0
|
73
|
+
m_Script: {fileID: 11500000, guid: f035c5c32b7f4cc7b57b4d8e05006a35, type: 3}
|
74
|
+
m_Name:
|
75
|
+
m_EditorClassIdentifier:
|
76
|
+
PlayerCam: {fileID: 4018879618047319413}
|
77
|
+
_moveSpeed: 5
|
78
|
+
_gravityScale: 20
|
79
|
+
_groundFriction: 7
|
80
|
+
_shiftMultiplier: 1.3
|
81
|
+
_runAcceleration: 24
|
82
|
+
_runDeacceleration: 12
|
83
|
+
_jumpSpeed: 6
|
84
|
+
_maxSpeed: 1
|
85
|
+
_airAcceleration: 4
|
86
|
+
_airDecceleration: 1
|
87
|
+
_airControl: 0
|
88
|
+
_mouseSensitivity: {x: 80, y: 80}
|
89
|
+
_invertX: 0
|
90
|
+
_invertY: 0
|
91
|
+
--- !u!114 &2393812327530706906
|
92
|
+
MonoBehaviour:
|
93
|
+
m_ObjectHideFlags: 0
|
94
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
95
|
+
m_PrefabInstance: {fileID: 0}
|
96
|
+
m_PrefabAsset: {fileID: 0}
|
97
|
+
m_GameObject: {fileID: 1169133041383888513}
|
98
|
+
m_Enabled: 1
|
99
|
+
m_EditorHideFlags: 0
|
100
|
+
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
|
101
|
+
m_Name:
|
102
|
+
m_EditorClassIdentifier:
|
103
|
+
m_Actions: {fileID: -944628639613478452, guid: 052faaac586de48259a63d0c4782560b, type: 3}
|
104
|
+
m_NotificationBehavior: 0
|
105
|
+
m_UIInputModule: {fileID: 0}
|
106
|
+
m_DeviceLostEvent:
|
107
|
+
m_PersistentCalls:
|
108
|
+
m_Calls: []
|
109
|
+
m_DeviceRegainedEvent:
|
110
|
+
m_PersistentCalls:
|
111
|
+
m_Calls: []
|
112
|
+
m_ControlsChangedEvent:
|
113
|
+
m_PersistentCalls:
|
114
|
+
m_Calls: []
|
115
|
+
m_ActionEvents: []
|
116
|
+
m_NeverAutoSwitchControlSchemes: 0
|
117
|
+
m_DefaultControlScheme:
|
118
|
+
m_DefaultActionMap: Player
|
119
|
+
m_SplitScreenIndex: -1
|
120
|
+
m_Camera: {fileID: 0}
|
121
|
+
--- !u!1 &5117732307083995164
|
122
|
+
GameObject:
|
123
|
+
m_ObjectHideFlags: 0
|
124
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
125
|
+
m_PrefabInstance: {fileID: 0}
|
126
|
+
m_PrefabAsset: {fileID: 0}
|
127
|
+
serializedVersion: 6
|
128
|
+
m_Component:
|
129
|
+
- component: {fileID: 4083866799769892690}
|
130
|
+
- component: {fileID: 9157117107467866696}
|
131
|
+
- component: {fileID: 8921055407891754412}
|
132
|
+
- component: {fileID: 7769740293180514945}
|
133
|
+
m_Layer: 0
|
134
|
+
m_Name: Cube
|
135
|
+
m_TagString: Untagged
|
136
|
+
m_Icon: {fileID: 0}
|
137
|
+
m_NavMeshLayer: 0
|
138
|
+
m_StaticEditorFlags: 0
|
139
|
+
m_IsActive: 1
|
140
|
+
--- !u!4 &4083866799769892690
|
141
|
+
Transform:
|
142
|
+
m_ObjectHideFlags: 0
|
143
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
144
|
+
m_PrefabInstance: {fileID: 0}
|
145
|
+
m_PrefabAsset: {fileID: 0}
|
146
|
+
m_GameObject: {fileID: 5117732307083995164}
|
147
|
+
serializedVersion: 2
|
148
|
+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
149
|
+
m_LocalPosition: {x: 0, y: 0.435, z: 0.311}
|
150
|
+
m_LocalScale: {x: 0.46173453, y: 0.3749557, z: 0.43741}
|
151
|
+
m_ConstrainProportionsScale: 0
|
152
|
+
m_Children: []
|
153
|
+
m_Father: {fileID: 293513943171419127}
|
154
|
+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
155
|
+
--- !u!33 &9157117107467866696
|
156
|
+
MeshFilter:
|
157
|
+
m_ObjectHideFlags: 0
|
158
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
159
|
+
m_PrefabInstance: {fileID: 0}
|
160
|
+
m_PrefabAsset: {fileID: 0}
|
161
|
+
m_GameObject: {fileID: 5117732307083995164}
|
162
|
+
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
163
|
+
--- !u!23 &8921055407891754412
|
164
|
+
MeshRenderer:
|
165
|
+
m_ObjectHideFlags: 0
|
166
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
167
|
+
m_PrefabInstance: {fileID: 0}
|
168
|
+
m_PrefabAsset: {fileID: 0}
|
169
|
+
m_GameObject: {fileID: 5117732307083995164}
|
170
|
+
m_Enabled: 1
|
171
|
+
m_CastShadows: 1
|
172
|
+
m_ReceiveShadows: 1
|
173
|
+
m_DynamicOccludee: 1
|
174
|
+
m_StaticShadowCaster: 0
|
175
|
+
m_MotionVectors: 1
|
176
|
+
m_LightProbeUsage: 1
|
177
|
+
m_ReflectionProbeUsage: 1
|
178
|
+
m_RayTracingMode: 2
|
179
|
+
m_RayTraceProcedural: 0
|
180
|
+
m_RayTracingAccelStructBuildFlagsOverride: 0
|
181
|
+
m_RayTracingAccelStructBuildFlags: 1
|
182
|
+
m_SmallMeshCulling: 1
|
183
|
+
m_RenderingLayerMask: 1
|
184
|
+
m_RendererPriority: 0
|
185
|
+
m_Materials:
|
186
|
+
- {fileID: 2100000, guid: c2e40fa84d53ccd428f640eac126b1fb, type: 2}
|
187
|
+
m_StaticBatchInfo:
|
188
|
+
firstSubMesh: 0
|
189
|
+
subMeshCount: 0
|
190
|
+
m_StaticBatchRoot: {fileID: 0}
|
191
|
+
m_ProbeAnchor: {fileID: 0}
|
192
|
+
m_LightProbeVolumeOverride: {fileID: 0}
|
193
|
+
m_ScaleInLightmap: 1
|
194
|
+
m_ReceiveGI: 1
|
195
|
+
m_PreserveUVs: 0
|
196
|
+
m_IgnoreNormalsForChartDetection: 0
|
197
|
+
m_ImportantGI: 0
|
198
|
+
m_StitchLightmapSeams: 1
|
199
|
+
m_SelectedEditorRenderState: 3
|
200
|
+
m_MinimumChartSize: 4
|
201
|
+
m_AutoUVMaxDistance: 0.5
|
202
|
+
m_AutoUVMaxAngle: 89
|
203
|
+
m_LightmapParameters: {fileID: 0}
|
204
|
+
m_SortingLayerID: 0
|
205
|
+
m_SortingLayer: 0
|
206
|
+
m_SortingOrder: 0
|
207
|
+
m_AdditionalVertexStreams: {fileID: 0}
|
208
|
+
--- !u!65 &7769740293180514945
|
209
|
+
BoxCollider:
|
210
|
+
m_ObjectHideFlags: 0
|
211
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
212
|
+
m_PrefabInstance: {fileID: 0}
|
213
|
+
m_PrefabAsset: {fileID: 0}
|
214
|
+
m_GameObject: {fileID: 5117732307083995164}
|
215
|
+
m_Material: {fileID: 0}
|
216
|
+
m_IncludeLayers:
|
217
|
+
serializedVersion: 2
|
218
|
+
m_Bits: 0
|
219
|
+
m_ExcludeLayers:
|
220
|
+
serializedVersion: 2
|
221
|
+
m_Bits: 0
|
222
|
+
m_LayerOverridePriority: 0
|
223
|
+
m_IsTrigger: 0
|
224
|
+
m_ProvidesContacts: 0
|
225
|
+
m_Enabled: 1
|
226
|
+
serializedVersion: 3
|
227
|
+
m_Size: {x: 1, y: 1, z: 1}
|
228
|
+
m_Center: {x: 0, y: 0, z: 0}
|
229
|
+
--- !u!1 &8291206075886104601
|
230
|
+
GameObject:
|
231
|
+
m_ObjectHideFlags: 0
|
232
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
233
|
+
m_PrefabInstance: {fileID: 0}
|
234
|
+
m_PrefabAsset: {fileID: 0}
|
235
|
+
serializedVersion: 6
|
236
|
+
m_Component:
|
237
|
+
- component: {fileID: 293513943171419127}
|
238
|
+
- component: {fileID: 4469209499644079421}
|
239
|
+
- component: {fileID: 9168726561999561945}
|
240
|
+
m_Layer: 0
|
241
|
+
m_Name: mesh
|
242
|
+
m_TagString: Untagged
|
243
|
+
m_Icon: {fileID: 0}
|
244
|
+
m_NavMeshLayer: 0
|
245
|
+
m_StaticEditorFlags: 0
|
246
|
+
m_IsActive: 1
|
247
|
+
--- !u!4 &293513943171419127
|
248
|
+
Transform:
|
249
|
+
m_ObjectHideFlags: 0
|
250
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
251
|
+
m_PrefabInstance: {fileID: 0}
|
252
|
+
m_PrefabAsset: {fileID: 0}
|
253
|
+
m_GameObject: {fileID: 8291206075886104601}
|
254
|
+
serializedVersion: 2
|
255
|
+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
256
|
+
m_LocalPosition: {x: 0, y: 1, z: 0}
|
257
|
+
m_LocalScale: {x: 1, y: 1, z: 1}
|
258
|
+
m_ConstrainProportionsScale: 0
|
259
|
+
m_Children:
|
260
|
+
- {fileID: 4083866799769892690}
|
261
|
+
m_Father: {fileID: 379312770605712307}
|
262
|
+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
263
|
+
--- !u!33 &4469209499644079421
|
264
|
+
MeshFilter:
|
265
|
+
m_ObjectHideFlags: 0
|
266
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
267
|
+
m_PrefabInstance: {fileID: 0}
|
268
|
+
m_PrefabAsset: {fileID: 0}
|
269
|
+
m_GameObject: {fileID: 8291206075886104601}
|
270
|
+
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
|
271
|
+
--- !u!23 &9168726561999561945
|
272
|
+
MeshRenderer:
|
273
|
+
m_ObjectHideFlags: 0
|
274
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
275
|
+
m_PrefabInstance: {fileID: 0}
|
276
|
+
m_PrefabAsset: {fileID: 0}
|
277
|
+
m_GameObject: {fileID: 8291206075886104601}
|
278
|
+
m_Enabled: 1
|
279
|
+
m_CastShadows: 1
|
280
|
+
m_ReceiveShadows: 1
|
281
|
+
m_DynamicOccludee: 1
|
282
|
+
m_StaticShadowCaster: 0
|
283
|
+
m_MotionVectors: 1
|
284
|
+
m_LightProbeUsage: 1
|
285
|
+
m_ReflectionProbeUsage: 1
|
286
|
+
m_RayTracingMode: 2
|
287
|
+
m_RayTraceProcedural: 0
|
288
|
+
m_RayTracingAccelStructBuildFlagsOverride: 0
|
289
|
+
m_RayTracingAccelStructBuildFlags: 1
|
290
|
+
m_SmallMeshCulling: 1
|
291
|
+
m_RenderingLayerMask: 1
|
292
|
+
m_RendererPriority: 0
|
293
|
+
m_Materials:
|
294
|
+
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
|
295
|
+
m_StaticBatchInfo:
|
296
|
+
firstSubMesh: 0
|
297
|
+
subMeshCount: 0
|
298
|
+
m_StaticBatchRoot: {fileID: 0}
|
299
|
+
m_ProbeAnchor: {fileID: 0}
|
300
|
+
m_LightProbeVolumeOverride: {fileID: 0}
|
301
|
+
m_ScaleInLightmap: 1
|
302
|
+
m_ReceiveGI: 1
|
303
|
+
m_PreserveUVs: 0
|
304
|
+
m_IgnoreNormalsForChartDetection: 0
|
305
|
+
m_ImportantGI: 0
|
306
|
+
m_StitchLightmapSeams: 1
|
307
|
+
m_SelectedEditorRenderState: 3
|
308
|
+
m_MinimumChartSize: 4
|
309
|
+
m_AutoUVMaxDistance: 0.5
|
310
|
+
m_AutoUVMaxAngle: 89
|
311
|
+
m_LightmapParameters: {fileID: 0}
|
312
|
+
m_SortingLayerID: 0
|
313
|
+
m_SortingLayer: 0
|
314
|
+
m_SortingOrder: 0
|
315
|
+
m_AdditionalVertexStreams: {fileID: 0}
|
316
|
+
--- !u!1 &8803302391748770143
|
317
|
+
GameObject:
|
318
|
+
m_ObjectHideFlags: 0
|
319
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
320
|
+
m_PrefabInstance: {fileID: 0}
|
321
|
+
m_PrefabAsset: {fileID: 0}
|
322
|
+
serializedVersion: 6
|
323
|
+
m_Component:
|
324
|
+
- component: {fileID: 4018879618047319413}
|
325
|
+
- component: {fileID: 1922714351363115592}
|
326
|
+
- component: {fileID: 7330681982857037467}
|
327
|
+
- component: {fileID: 1232422153327259658}
|
328
|
+
m_Layer: 0
|
329
|
+
m_Name: Main Camera
|
330
|
+
m_TagString: MainCamera
|
331
|
+
m_Icon: {fileID: 0}
|
332
|
+
m_NavMeshLayer: 0
|
333
|
+
m_StaticEditorFlags: 0
|
334
|
+
m_IsActive: 1
|
335
|
+
--- !u!4 &4018879618047319413
|
336
|
+
Transform:
|
337
|
+
m_ObjectHideFlags: 0
|
338
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
339
|
+
m_PrefabInstance: {fileID: 0}
|
340
|
+
m_PrefabAsset: {fileID: 0}
|
341
|
+
m_GameObject: {fileID: 8803302391748770143}
|
342
|
+
serializedVersion: 2
|
343
|
+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
344
|
+
m_LocalPosition: {x: 0, y: 1.6, z: 0.3}
|
345
|
+
m_LocalScale: {x: 1, y: 1, z: 1}
|
346
|
+
m_ConstrainProportionsScale: 0
|
347
|
+
m_Children: []
|
348
|
+
m_Father: {fileID: 379312770605712307}
|
349
|
+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
350
|
+
--- !u!20 &1922714351363115592
|
351
|
+
Camera:
|
352
|
+
m_ObjectHideFlags: 0
|
353
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
354
|
+
m_PrefabInstance: {fileID: 0}
|
355
|
+
m_PrefabAsset: {fileID: 0}
|
356
|
+
m_GameObject: {fileID: 8803302391748770143}
|
357
|
+
m_Enabled: 1
|
358
|
+
serializedVersion: 2
|
359
|
+
m_ClearFlags: 1
|
360
|
+
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
361
|
+
m_projectionMatrixMode: 1
|
362
|
+
m_GateFitMode: 2
|
363
|
+
m_FOVAxisMode: 0
|
364
|
+
m_Iso: 200
|
365
|
+
m_ShutterSpeed: 0.005
|
366
|
+
m_Aperture: 16
|
367
|
+
m_FocusDistance: 10
|
368
|
+
m_FocalLength: 50
|
369
|
+
m_BladeCount: 5
|
370
|
+
m_Curvature: {x: 2, y: 11}
|
371
|
+
m_BarrelClipping: 0.25
|
372
|
+
m_Anamorphism: 0
|
373
|
+
m_SensorSize: {x: 36, y: 24}
|
374
|
+
m_LensShift: {x: 0, y: 0}
|
375
|
+
m_NormalizedViewPortRect:
|
376
|
+
serializedVersion: 2
|
377
|
+
x: 0
|
378
|
+
y: 0
|
379
|
+
width: 1
|
380
|
+
height: 1
|
381
|
+
near clip plane: 0.1
|
382
|
+
far clip plane: 1000
|
383
|
+
field of view: 70
|
384
|
+
orthographic: 0
|
385
|
+
orthographic size: 5
|
386
|
+
m_Depth: -1
|
387
|
+
m_CullingMask:
|
388
|
+
serializedVersion: 2
|
389
|
+
m_Bits: 4294967295
|
390
|
+
m_RenderingPath: -1
|
391
|
+
m_TargetTexture: {fileID: 0}
|
392
|
+
m_TargetDisplay: 0
|
393
|
+
m_TargetEye: 3
|
394
|
+
m_HDR: 1
|
395
|
+
m_AllowMSAA: 1
|
396
|
+
m_AllowDynamicResolution: 0
|
397
|
+
m_ForceIntoRT: 0
|
398
|
+
m_OcclusionCulling: 1
|
399
|
+
m_StereoConvergence: 10
|
400
|
+
m_StereoSeparation: 0.022
|
401
|
+
--- !u!81 &7330681982857037467
|
402
|
+
AudioListener:
|
403
|
+
m_ObjectHideFlags: 0
|
404
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
405
|
+
m_PrefabInstance: {fileID: 0}
|
406
|
+
m_PrefabAsset: {fileID: 0}
|
407
|
+
m_GameObject: {fileID: 8803302391748770143}
|
408
|
+
m_Enabled: 1
|
409
|
+
--- !u!114 &1232422153327259658
|
410
|
+
MonoBehaviour:
|
411
|
+
m_ObjectHideFlags: 0
|
412
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
413
|
+
m_PrefabInstance: {fileID: 0}
|
414
|
+
m_PrefabAsset: {fileID: 0}
|
415
|
+
m_GameObject: {fileID: 8803302391748770143}
|
416
|
+
m_Enabled: 1
|
417
|
+
m_EditorHideFlags: 0
|
418
|
+
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
|
419
|
+
m_Name:
|
420
|
+
m_EditorClassIdentifier:
|
421
|
+
m_RenderShadows: 1
|
422
|
+
m_RequiresDepthTextureOption: 2
|
423
|
+
m_RequiresOpaqueTextureOption: 2
|
424
|
+
m_CameraType: 0
|
425
|
+
m_Cameras: []
|
426
|
+
m_RendererIndex: -1
|
427
|
+
m_VolumeLayerMask:
|
428
|
+
serializedVersion: 2
|
429
|
+
m_Bits: 1
|
430
|
+
m_VolumeTrigger: {fileID: 0}
|
431
|
+
m_VolumeFrameworkUpdateModeOption: 2
|
432
|
+
m_RenderPostProcessing: 1
|
433
|
+
m_Antialiasing: 0
|
434
|
+
m_AntialiasingQuality: 2
|
435
|
+
m_StopNaN: 1
|
436
|
+
m_Dithering: 0
|
437
|
+
m_ClearDepth: 1
|
438
|
+
m_AllowXRRendering: 1
|
439
|
+
m_AllowHDROutput: 1
|
440
|
+
m_UseScreenCoordOverride: 0
|
441
|
+
m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0}
|
442
|
+
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
|
443
|
+
m_RequiresDepthTexture: 0
|
444
|
+
m_RequiresColorTexture: 0
|
445
|
+
m_Version: 2
|
446
|
+
m_TaaSettings:
|
447
|
+
m_Quality: 3
|
448
|
+
m_FrameInfluence: 0.1
|
449
|
+
m_JitterScale: 1
|
450
|
+
m_MipBias: 0
|
451
|
+
m_VarianceClampScale: 0.9
|
452
|
+
m_ContrastAdaptiveSharpening: 0
|
@@ -0,0 +1,141 @@
|
|
1
|
+
using UnityEngine;
|
2
|
+
using UnityEngine.InputSystem;
|
3
|
+
|
4
|
+
namespace Game.FirstPersonMovement
|
5
|
+
{
|
6
|
+
[RequireComponent(typeof(CharacterController))]
|
7
|
+
public class PlayerMovement : MonoBehaviour
|
8
|
+
{
|
9
|
+
public Transform PlayerCam;
|
10
|
+
|
11
|
+
[Header("Movement")]
|
12
|
+
[SerializeField] private float _moveSpeed = 7.0f;
|
13
|
+
[SerializeField] private float _gravityScale = 20f;
|
14
|
+
[SerializeField] private float _groundFriction = 6f;
|
15
|
+
[SerializeField] private float _shiftMultiplier = 0.5f;
|
16
|
+
[SerializeField] private float _runAcceleration = 14f;
|
17
|
+
[SerializeField] private float _runDeacceleration = 10f;
|
18
|
+
[SerializeField] private float _jumpSpeed = 8f;
|
19
|
+
[SerializeField] private float _maxSpeed;
|
20
|
+
[SerializeField] private float _airAcceleration = 2f;
|
21
|
+
[SerializeField] private float _airDecceleration = 2f;
|
22
|
+
[SerializeField] private float _airControl = 0.3f;
|
23
|
+
|
24
|
+
[Header("Camera")]
|
25
|
+
[SerializeField] private Vector2 _mouseSensitivity = new Vector2(30, 30);
|
26
|
+
[SerializeField] private bool _invertX;
|
27
|
+
[SerializeField] private bool _invertY;
|
28
|
+
|
29
|
+
private float _xRot;
|
30
|
+
private float _yRot = -90;
|
31
|
+
|
32
|
+
private CharacterController _characterController;
|
33
|
+
private PlayerInput _playerInput;
|
34
|
+
|
35
|
+
private bool _wishJump;
|
36
|
+
private Vector3 _velocity;
|
37
|
+
private Vector2 _moveInput;
|
38
|
+
private Vector2 _lookInput;
|
39
|
+
|
40
|
+
public bool IsGrounded => _characterController?.isGrounded ?? false;
|
41
|
+
public Vector3 Velocity => _velocity;
|
42
|
+
|
43
|
+
private void Start()
|
44
|
+
{
|
45
|
+
Cursor.visible = false;
|
46
|
+
Cursor.lockState = CursorLockMode.Locked;
|
47
|
+
|
48
|
+
_characterController = GetComponent<CharacterController>();
|
49
|
+
_playerInput = GetComponent<PlayerInput>();
|
50
|
+
}
|
51
|
+
|
52
|
+
private void Update()
|
53
|
+
{
|
54
|
+
_moveInput = _playerInput.actions["Move"].ReadValue<Vector2>();
|
55
|
+
_lookInput = _playerInput.actions["Look"].ReadValue<Vector2>();
|
56
|
+
|
57
|
+
Look();
|
58
|
+
|
59
|
+
if (_playerInput.actions["Jump"].WasPerformedThisFrame() && IsGrounded)
|
60
|
+
{
|
61
|
+
_wishJump = true;
|
62
|
+
}
|
63
|
+
|
64
|
+
if (_characterController.isGrounded)
|
65
|
+
GroundMovement();
|
66
|
+
else
|
67
|
+
AirMovement();
|
68
|
+
|
69
|
+
_characterController.Move(_velocity * Time.unscaledDeltaTime);
|
70
|
+
}
|
71
|
+
|
72
|
+
private void GroundMovement()
|
73
|
+
{
|
74
|
+
_velocity = MovementHelper.ApplyFriction(_velocity, _groundFriction, _runDeacceleration, !_wishJump ? 1f : 0);
|
75
|
+
|
76
|
+
Vector3 wishDir = new Vector3(_moveInput.x, 0, _moveInput.y);
|
77
|
+
wishDir = transform.TransformDirection(wishDir);
|
78
|
+
wishDir = wishDir.normalized;
|
79
|
+
|
80
|
+
float wishSpeed = wishDir.magnitude;
|
81
|
+
wishSpeed *= _moveSpeed;
|
82
|
+
|
83
|
+
if (_playerInput.actions["Sprint"].IsPressed())
|
84
|
+
{
|
85
|
+
wishSpeed *= _shiftMultiplier;
|
86
|
+
}
|
87
|
+
|
88
|
+
_velocity = MovementHelper.Accelerate(_velocity, wishDir, wishSpeed, _runAcceleration);
|
89
|
+
|
90
|
+
if (_wishJump)
|
91
|
+
{
|
92
|
+
_velocity.y = _jumpSpeed;
|
93
|
+
_wishJump = false;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
private void AirMovement()
|
98
|
+
{
|
99
|
+
Vector3 wishDir = new Vector3(_moveInput.x, 0, _moveInput.y);
|
100
|
+
wishDir = transform.TransformDirection(wishDir);
|
101
|
+
wishDir = wishDir.normalized;
|
102
|
+
|
103
|
+
float wishSpeed = wishDir.magnitude;
|
104
|
+
wishSpeed *= _moveSpeed;
|
105
|
+
|
106
|
+
float accel = Vector3.Dot(_velocity, wishDir) < 0 ? _airDecceleration : _airAcceleration;
|
107
|
+
|
108
|
+
float wishSpeed2 = wishSpeed;
|
109
|
+
if (_maxSpeed > 0 && wishSpeed > _maxSpeed)
|
110
|
+
wishSpeed = _maxSpeed;
|
111
|
+
|
112
|
+
_velocity = MovementHelper.Accelerate(_velocity, wishDir, wishSpeed, accel);
|
113
|
+
|
114
|
+
if (_airControl > 0)
|
115
|
+
{
|
116
|
+
_velocity = MovementHelper.AirControl(_velocity, wishDir, _airControl, wishSpeed2);
|
117
|
+
}
|
118
|
+
|
119
|
+
_velocity.y -= _gravityScale * Time.unscaledDeltaTime;
|
120
|
+
}
|
121
|
+
|
122
|
+
private void Look()
|
123
|
+
{
|
124
|
+
float xSensitivity = _mouseSensitivity.x;
|
125
|
+
float ySensitivity = _mouseSensitivity.y;
|
126
|
+
xSensitivity = _invertX ? -xSensitivity : xSensitivity;
|
127
|
+
ySensitivity = _invertY ? -ySensitivity : ySensitivity;
|
128
|
+
|
129
|
+
_xRot -= (_lookInput.y * Time.unscaledDeltaTime) * xSensitivity * 0.5f;
|
130
|
+
_yRot += (_lookInput.x * Time.unscaledDeltaTime) * ySensitivity * 0.5f;
|
131
|
+
|
132
|
+
if (_xRot < -90)
|
133
|
+
_xRot = -90;
|
134
|
+
else if (_xRot > 90)
|
135
|
+
_xRot = 90;
|
136
|
+
|
137
|
+
transform.rotation = Quaternion.Euler(0, _yRot, 0);
|
138
|
+
PlayerCam.rotation = Quaternion.Euler(_xRot, _yRot, 0);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
package/Runtime.meta
ADDED
package/package.json
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"name": "com.steelboxgames.firstpersonmovement",
|
3
|
+
"version": "1.0.4",
|
4
|
+
"displayName": "First Person Movement",
|
5
|
+
"description": "First person player movement for base setup.",
|
6
|
+
"unity": "6.1",
|
7
|
+
"author": {
|
8
|
+
"name": "Isaac Holloway",
|
9
|
+
"email": "isaacholloway.code@gmail.com",
|
10
|
+
"url": "https://www.codesteel.io/"
|
11
|
+
},
|
12
|
+
"com.steelboxgames.firstpersonmovement": "1.0.4",
|
13
|
+
"repository": {
|
14
|
+
"type": "git",
|
15
|
+
"url": "https://github.com/steelboxgames/com.steelboxgames.firstpersonmovement.git",
|
16
|
+
"directory": "com.steelboxgames.firstpersonmovement"
|
17
|
+
},
|
18
|
+
"keywords": ["unity", "firstperson", "controller"],
|
19
|
+
"type": "library"
|
20
|
+
}
|