奔跑功能
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user