奔跑功能

This commit is contained in:
2025-05-18 18:27:54 +08:00
parent 4a614b6a21
commit 62886b46e9
5 changed files with 46177 additions and 46115 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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

View File

@@ -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)

View File

@@ -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;