奔跑功能
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -9844,10 +9844,10 @@ CapsuleCollider:
|
||||
m_ProvidesContacts: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Radius: 0.5
|
||||
m_Height: 2
|
||||
m_Radius: 0.3
|
||||
m_Height: 1.8
|
||||
m_Direction: 1
|
||||
m_Center: {x: 0, y: 1, z: 0}
|
||||
m_Center: {x: 0, y: 0.9, z: 0}
|
||||
--- !u!114 &7406758408172975810
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -9863,11 +9863,11 @@ MonoBehaviour:
|
||||
_planeConstraint: 0
|
||||
_rootTransform: {fileID: 0}
|
||||
_rootTransformOffset: {x: 0, y: 0, z: 0}
|
||||
_radius: 0.5
|
||||
_height: 2
|
||||
_radius: 0.3
|
||||
_height: 1.8
|
||||
_slopeLimit: 45
|
||||
_stepOffset: 0.45
|
||||
_perchOffset: 0.5
|
||||
_perchOffset: 0.3
|
||||
_perchAdditionalHeight: 0.4
|
||||
_slopeLimitOverride: 0
|
||||
_useFlatTop: 0
|
||||
@@ -9902,7 +9902,7 @@ MonoBehaviour:
|
||||
_rotationMode: 0
|
||||
_rotationRate: 540
|
||||
_startingMovementMode: 1
|
||||
_maxWalkSpeed: 5
|
||||
_maxWalkSpeed: 3
|
||||
_minAnalogWalkSpeed: 0
|
||||
_maxAcceleration: 20
|
||||
_brakingDecelerationWalking: 20
|
||||
@@ -9942,13 +9942,14 @@ MonoBehaviour:
|
||||
_pushForceScale: 1
|
||||
_standingDownwardForceScale: 1
|
||||
_camera: {fileID: 0}
|
||||
nextShowSlotIndex: -1
|
||||
maxSprintSpeed: 5
|
||||
cameraParent: {fileID: 8796494894830104914}
|
||||
invertLook: 1
|
||||
sensitivity: {x: 0.05, y: 0.05}
|
||||
sensitivity: {x: 0.02, y: 0.02}
|
||||
minPitch: -45
|
||||
maxPitch: 80
|
||||
handMaxAngle: {x: 25, y: -25}
|
||||
nextShowSlotIndex: -1
|
||||
IsSelf: 0
|
||||
lookAtIK: {fileID: 0}
|
||||
aimDistance: 1.5
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace NBF
|
||||
public static bool IsOp1;
|
||||
public static bool IsOp2;
|
||||
|
||||
public static bool IsRunning;
|
||||
|
||||
public static event Action<bool> OnOp1Action;
|
||||
public static event Action<bool> OnOp2Action;
|
||||
@@ -96,6 +95,10 @@ namespace NBF
|
||||
/// </summary>
|
||||
public static event Action<bool> OnMapAction;
|
||||
|
||||
/// <summary>
|
||||
/// 奔跑
|
||||
/// </summary>
|
||||
public static event Action<bool> OnRunAction;
|
||||
|
||||
public static PlayerInputControl PlayerInputControl { get; private set; }
|
||||
|
||||
@@ -270,7 +273,7 @@ namespace NBF
|
||||
|
||||
private void OnRun(InputAction.CallbackContext context)
|
||||
{
|
||||
IsRunning = context.performed;
|
||||
OnRunAction?.Invoke(context.performed);
|
||||
}
|
||||
|
||||
private void OnOp1(InputAction.CallbackContext context)
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace NBF
|
||||
private FPlayer _player;
|
||||
private float _defBackSpineZ;
|
||||
|
||||
[HideInInspector] public int nextShowSlotIndex = -1;
|
||||
|
||||
[Space(10.0f)] public float maxSprintSpeed = 10.0f;
|
||||
|
||||
public GameObject cameraParent;
|
||||
[Space(15.0f)] public bool invertLook = true;
|
||||
@@ -22,7 +22,7 @@ namespace NBF
|
||||
public float maxPitch = 80.0f;
|
||||
|
||||
[Tooltip("手上下最大角度")] public Vector2 handMaxAngle = new Vector2(0, 0);
|
||||
|
||||
[HideInInspector] public int nextShowSlotIndex = -1;
|
||||
public bool IsSelf;
|
||||
|
||||
private Quaternion spineInitialLocalRotation;
|
||||
@@ -40,7 +40,7 @@ namespace NBF
|
||||
base.Start();
|
||||
|
||||
// 创建一个动态目标点对象,避免你每次动态生成
|
||||
|
||||
|
||||
lookAtIK = GetComponent<LookAtIK>();
|
||||
_player = GetComponent<FPlayer>();
|
||||
IsSelf = _player.Data.PlayerID == GameModel.RoleID;
|
||||
@@ -52,14 +52,14 @@ namespace NBF
|
||||
|
||||
lookTarget = new GameObject("SpineLookTarget").transform;
|
||||
lookTarget.SetParent(_player.transform);
|
||||
|
||||
|
||||
spineInitialLocalRotation = _player.BackSpine.localRotation;
|
||||
_defBackSpineZ = -AnglesChange(_player.BackSpine.localEulerAngles.z);
|
||||
transform.position = _player.Data.position;
|
||||
transform.rotation = _player.Data.rotation;
|
||||
|
||||
App.Inst.SetMouseCurrsor(false);
|
||||
|
||||
InputManager.OnRunAction += OnRunAction;
|
||||
InputManager.OnQuickIndexAction += OnQuickIndexAction;
|
||||
InputManager.OnUseTorchAction += OnUseTorchAction;
|
||||
InputManager.OnUseTelescopeAction += OnUseTelescopeAction;
|
||||
@@ -71,6 +71,12 @@ namespace NBF
|
||||
UpdateGear();
|
||||
}
|
||||
|
||||
protected override void OnBeforeSimulationUpdate(float deltaTime)
|
||||
{
|
||||
base.OnBeforeSimulationUpdate(deltaTime);
|
||||
CheckSprintInput();
|
||||
}
|
||||
|
||||
protected virtual void LateUpdate()
|
||||
{
|
||||
UpdateCameraParentRotation();
|
||||
@@ -82,6 +88,7 @@ namespace NBF
|
||||
{
|
||||
base.Reset();
|
||||
SetRotationMode(RotationMode.None);
|
||||
StopSprinting();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -135,6 +142,9 @@ namespace NBF
|
||||
|
||||
#region 角色位移和旋转控制
|
||||
|
||||
private bool _isSprinting;
|
||||
private bool _sprintInputPressed;
|
||||
|
||||
private void UpdatePlayerPositionAndRotation()
|
||||
{
|
||||
// Move
|
||||
@@ -185,10 +195,58 @@ namespace NBF
|
||||
cameraParent.transform.localRotation = Quaternion.Euler(_cameraPitch, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
public void Sprint()
|
||||
{
|
||||
_sprintInputPressed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the character to stop sprinting.
|
||||
/// </summary>
|
||||
public void StopSprinting()
|
||||
{
|
||||
_sprintInputPressed = false;
|
||||
}
|
||||
|
||||
public bool IsSprinting()
|
||||
{
|
||||
return _isSprinting;
|
||||
}
|
||||
|
||||
private bool CanSprint()
|
||||
{
|
||||
return IsWalking() && !IsCrouched();
|
||||
}
|
||||
|
||||
|
||||
private void CheckSprintInput()
|
||||
{
|
||||
if (!_isSprinting && _sprintInputPressed && CanSprint())
|
||||
{
|
||||
_isSprinting = true;
|
||||
}
|
||||
else if (_isSprinting && (!_sprintInputPressed || !CanSprint()))
|
||||
{
|
||||
_isSprinting = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetMaxSpeed()
|
||||
{
|
||||
return _isSprinting ? maxSprintSpeed : base.GetMaxSpeed();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 按键输入事件
|
||||
|
||||
private void OnRunAction(bool performed)
|
||||
{
|
||||
if (performed) Sprint();
|
||||
else StopSprinting();
|
||||
}
|
||||
|
||||
private void OnQuickIndexAction(int index)
|
||||
{
|
||||
nextShowSlotIndex = index;
|
||||
|
||||
@@ -9,32 +9,32 @@ EditorUserSettings:
|
||||
value: 18134705175a055722080a3115371d4a0d55006876786860616b0471b8b07a68ffab74f9ee2a3a30300cea1a11320d0beb1a0c25f7060f494b4cc80018eb09361fc211cb1f862d19c51d19dcc413d6ade0d8ddfcddf9f4d9d29195fcfde6ebeae6f0a9c9afa6f8c5b89ff7a1aacececac4eba4d7c9d28bda
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-0:
|
||||
value: 55030157570d5108595b557213770a47434e4d7f797e27667e2a1963e6b2323b
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-1:
|
||||
value: 5407555107065c0c550a0d7645260e4410151a7e7a71706729781c31e6b86469
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-2:
|
||||
value: 05010d5107025b5d5b0f0a24487b5c44154f49787c7877612b7a4c35b1b86d69
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-3:
|
||||
RecentlyUsedSceneGuid-1:
|
||||
value: 5057005200535b5808565a75457a0b4414161b7b2e7e74322979186ab2e6323a
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-4:
|
||||
RecentlyUsedSceneGuid-2:
|
||||
value: 5403075056035e03540c0e7b467707411416492c7e292734752b456bb1b73161
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-5:
|
||||
RecentlyUsedSceneGuid-3:
|
||||
value: 0652525052015d5f5e5f0e7147700744464e4a7f2a2c72342f2d4930e0e66560
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-6:
|
||||
RecentlyUsedSceneGuid-4:
|
||||
value: 0150055704510808545c0a26467506444516197a747874637b7e1860b5b6616c
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-7:
|
||||
RecentlyUsedSceneGuid-5:
|
||||
value: 0705515f0650505f5457092744210e4440154a2c792c2434752f1862b6e6353e
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-8:
|
||||
RecentlyUsedSceneGuid-6:
|
||||
value: 5301070356065d0e5c0d5c73417759151016417a7b2d243275791e37e6b06160
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-7:
|
||||
value: 020056535456585e0f0d0a7541210d441215482c2d297f36752c1b65b3b0376e
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-8:
|
||||
value: 5305560255545f5f5f5d5d74427306444e154e2f7d2e7e66797b4862b4e3663c
|
||||
flags: 0
|
||||
RecentlyUsedSceneGuid-9:
|
||||
value: 5505015f5c515a085f5b092149760f441716407a787d7564287b1b36e7e1366e
|
||||
flags: 0
|
||||
|
||||
Reference in New Issue
Block a user