1
This commit is contained in:
@@ -22,7 +22,8 @@
|
||||
"GUID:87bea3a21c744b1478660b70494160ba",
|
||||
"GUID:9354affc93e0f3e4a904785e7d4c0f59",
|
||||
"GUID:55c64e242b053af47b2a7eae7bbeffad",
|
||||
"GUID:be8fc6f1c44f14943887ab6381170c28"
|
||||
"GUID:be8fc6f1c44f14943887ab6381170c28",
|
||||
"GUID:2dbcdde5f5df6a343a36c62f12bd6fae"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -7,6 +7,7 @@ using System.Timers;
|
||||
using BITFALL.Entities.Player.Movement.States;
|
||||
using BITFALL.Player.Equip;
|
||||
using BITFALL.Player.Movement;
|
||||
using BITFALL.Props;
|
||||
using BITFALL.Scene;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
@@ -29,7 +30,10 @@ namespace BITFALL.Entities.Player.Movement
|
||||
{
|
||||
[CustomType(typeof(IEntityMovement))]
|
||||
[CustomType(typeof(IPlayerMovement))]
|
||||
public class PlayerCharacterController : StateBasedPlayerBehavior<IEntityMovementState>,IEntityMovement,IPlayerMovement,IEntityBinaryComponent
|
||||
public class PlayerCharacterController : StateBasedPlayerBehavior<IEntityMovementState>
|
||||
,IEntityMovement
|
||||
,IPlayerMovement
|
||||
,IEntityBinaryComponent
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] internal Vector3 initialCameraPosition = new(0,0.11f,0.27f);
|
||||
@@ -77,7 +81,12 @@ namespace BITFALL.Entities.Player.Movement
|
||||
set => actor.Rotation = value;
|
||||
}
|
||||
|
||||
public float ReferenceSpeed { get; internal set; }
|
||||
public float ReferenceSpeed
|
||||
{
|
||||
get =>limitSpeed.Allow ? Mathf.Min(limitSpeed.Value,referenceSpeed):referenceSpeed;
|
||||
set=>referenceSpeed = value;
|
||||
}
|
||||
private float referenceSpeed = 2.5f;
|
||||
public Vector3 Forward => actor.Forward;
|
||||
public Vector3 ViewForward { get; set; }
|
||||
public Vector3 ViewCenter { get; private set; }
|
||||
@@ -109,8 +118,12 @@ namespace BITFALL.Entities.Player.Movement
|
||||
internal IOptional<float> limitSpeed =>new ReadOnlyOptional<float>(limitSpeedDictionary.Count is not 0,
|
||||
limitSpeedDictionary.Count is 0 ? 0 :
|
||||
limitSpeedDictionary.Values.Min());
|
||||
internal IOptional<float> limitSensitive => new ReadOnlyOptional<float>(limitSensitiveSpeedDictionary.Count is not 0,
|
||||
limitSensitiveSpeedDictionary.Count is 0 ? 0 :
|
||||
limitSensitiveSpeedDictionary.Values.Min() * 0.5f);
|
||||
|
||||
private readonly Dictionary<int,float> limitSpeedDictionary = new();
|
||||
private readonly Dictionary<int,float> limitSensitiveSpeedDictionary = new();
|
||||
|
||||
private bool isDead;
|
||||
internal bool topBlocked;
|
||||
@@ -286,6 +299,16 @@ namespace BITFALL.Entities.Player.Movement
|
||||
limitSpeedDictionary.TryRemove(limitMoveSpeedCommand.Id);
|
||||
}
|
||||
break;
|
||||
case PlayerLimitSensitivityCommand limitSensitivityCommand:
|
||||
if (limitSensitivityCommand.Limit)
|
||||
{
|
||||
limitSensitiveSpeedDictionary.Set(limitSensitivityCommand.Id,limitSensitivityCommand.Sensitivity);
|
||||
}
|
||||
else
|
||||
{
|
||||
limitSensitiveSpeedDictionary.TryRemove(limitSensitivityCommand.Id);
|
||||
}
|
||||
break;
|
||||
case PlayerDisableMovementCommand disableMovementCommand:
|
||||
allowMovement.SetDisableElements(disableMovementCommand.LockFile,disableMovementCommand.Disable);
|
||||
if (string.IsNullOrEmpty(disableMovementCommand.Source) is false && disableMovementCommand.Disable)
|
||||
@@ -312,7 +335,9 @@ namespace BITFALL.Entities.Player.Movement
|
||||
var playerConfig = PlayerConfig.Singleton;
|
||||
var ads = adsProvider.Get<float>();
|
||||
if (ads is 0) ads = 1;
|
||||
var raw = context.ReadValue<Vector2>() * playerConfig.Sensitivity * playerConfig.M_Yaw * ads;
|
||||
var raw = context.ReadValue<Vector2>() *
|
||||
(limitSensitive.Allow ? Mathf.Min( playerConfig.Sensitivity,limitSensitive.Value): playerConfig.Sensitivity)
|
||||
* playerConfig.M_Yaw * ads;
|
||||
LookInputDelta +=raw;
|
||||
var lookInput = LookInput;
|
||||
lookInput.x -= raw.y;
|
||||
@@ -527,6 +552,7 @@ namespace BITFALL.Entities.Player.Movement
|
||||
UpdateState(deltaTime);
|
||||
|
||||
CurrentState?.AfterUpdateMovement(deltaTime);
|
||||
|
||||
}
|
||||
|
||||
public override void OnFixedUpdate(float deltaTime)
|
||||
@@ -564,7 +590,7 @@ namespace BITFALL.Entities.Player.Movement
|
||||
actor.Velocity = default;
|
||||
}
|
||||
|
||||
var localVelocity = transform.InverseTransformDirection(Velocity) / initialSpeed;
|
||||
var localVelocity = transform.InverseTransformDirection(Velocity) / referenceSpeed;
|
||||
localVelocity.y = 0;
|
||||
LocomotionBasedVelocity = localVelocity;
|
||||
|
||||
@@ -760,12 +786,21 @@ namespace BITFALL.Entities.Player.Movement
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
if (CurrentState is not (IPlayerRunState or IPlayerSprintState or IPlayerClimbState or IPlayerVaultState or IPlayerLinkState)) return;
|
||||
if (CurrentState is not (
|
||||
IPlayerRunState
|
||||
or IPlayerSprintState
|
||||
or IPlayerClimbState
|
||||
or IPlayerVaultState
|
||||
or IPlayerLinkState
|
||||
or IPlayerSlideState
|
||||
)) return;
|
||||
if (other.collider.TryGetComponent<IScenePlayerImpact>(out var impact))
|
||||
{
|
||||
impact.OnPlayerImpact(Entity, transform.localToWorldMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Player.Movement;
|
||||
using BITFALL.Props;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEditor.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Entities.Player.Movement
|
||||
{
|
||||
[CustomType(typeof(IStunObject))]
|
||||
public class PlayerCharacterControllerStun : EntityBehavior,IStunObject
|
||||
{
|
||||
[Inject] private IEntityMovement _movement;
|
||||
[SerializeField] private float breatheFrequency = 0.5f; // 呼吸的频率,值越大呼吸越快
|
||||
[SerializeField] private float breatheAmplitude = 0.005f; // 呼吸的幅度,即准星上下移动的最大距离
|
||||
[SerializeField] private LocationAdditive viewAdditive;
|
||||
[SerializeField] private LocationAdditive inverseAdditive;
|
||||
private readonly ValidHandle allow = new();
|
||||
public float Weight { get;private set; }
|
||||
public event Action<float> OnWeightChanged;
|
||||
private readonly IntervalUpdate _resetInterval = new(1f);
|
||||
public async void Stun(float distance, float duration)
|
||||
{
|
||||
Weight = 1;
|
||||
OnWeightChanged?.Invoke(Weight);
|
||||
_resetInterval.AddDelay(duration);
|
||||
var id = Guid.NewGuid().GetHashCode();
|
||||
_movement.ExecuteCommand(new PlayerPauseRunCommand(id,true));
|
||||
_movement.ExecuteCommand(new PlayerLimitMoveSpeedCommand()
|
||||
{
|
||||
Id = id,
|
||||
Speed =1f,
|
||||
Limit = true,
|
||||
});
|
||||
_movement.ExecuteCommand(new PlayerLimitSensitivityCommand()
|
||||
{
|
||||
Id = id,
|
||||
Sensitivity = 0.1f,
|
||||
Limit = true,
|
||||
});
|
||||
allow.AddElement(id);
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(duration));
|
||||
if(destroyCancellationToken.IsCancellationRequested) return;
|
||||
_movement.ExecuteCommand(new PlayerPauseRunCommand(id,false));
|
||||
_movement.ExecuteCommand(new PlayerLimitMoveSpeedCommand()
|
||||
{
|
||||
Id = id,
|
||||
Limit = false,
|
||||
});
|
||||
_movement.ExecuteCommand(new PlayerLimitSensitivityCommand()
|
||||
{
|
||||
Id = id,
|
||||
Limit = false,
|
||||
});
|
||||
allow.RemoveElement(id);
|
||||
}
|
||||
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (Weight <= 0) return;
|
||||
|
||||
if(_resetInterval.AllowUpdateWithoutReset)
|
||||
{
|
||||
Weight = Mathf.Clamp(Weight -= deltaTime, 0, 1);
|
||||
OnWeightChanged?.Invoke(Weight);
|
||||
}
|
||||
|
||||
var breatheOffset = Mathf.Sin(Time.time * breatheFrequency) * breatheAmplitude;
|
||||
|
||||
breatheOffset *= Weight;
|
||||
if (viewAdditive)
|
||||
viewAdditive.AddRotation(Quaternion.Euler(breatheOffset, breatheOffset, 0), nameof(IStunObject));
|
||||
if (inverseAdditive)
|
||||
inverseAdditive.AddRotation(Quaternion.Euler(-breatheOffset, -breatheOffset, 0), nameof(IStunObject));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -510,6 +510,7 @@ namespace BITFALL.Entities.Player.Movement.States
|
||||
public override void AfterUpdateMovement(float deltaTime)
|
||||
{
|
||||
base.AfterUpdateMovement(deltaTime);
|
||||
if (Enabled is false) return;
|
||||
if (characterController.pauseRun.Allow)
|
||||
{
|
||||
characterController.TransitionState<Walk>();
|
||||
|
@@ -52,7 +52,7 @@ namespace BITFALL.Player.Animation
|
||||
{
|
||||
animator.animator.SetFloat(Vertical, _movement.LocomotionBasedVelocity.z);
|
||||
animator.animator.SetFloat(Horizontal, _movement.LocomotionBasedVelocity.x);
|
||||
animator.animator.SetFloat(SqrMagnitude, _movement.LocomotionBasedVelocity.sqrMagnitude);
|
||||
animator.animator.SetFloat(SqrMagnitude, _movement.Velocity.GetLength() / _movement.ReferenceSpeed);
|
||||
|
||||
animator.animator.SetFloat(Pitch,-MathV.TransientRotationAxis(_movement.ViewRotation.eulerAngles.x));
|
||||
|
||||
|
Reference in New Issue
Block a user