This commit is contained in:
CortexCore
2024-04-19 21:43:30 +08:00
parent e12a6e5a46
commit 3cc6491973
46 changed files with 6792 additions and 23887 deletions

View File

@@ -33,7 +33,8 @@ namespace BITFALL.Entities.Player.Movement
[CustomType(typeof(IEntityMovement))]
[CustomType(typeof(IPlayerMovement))]
[CustomType(typeof(ISensorTarget))]
public class PlayerCharacterController : StateBasedPlayerBehavior<IEntityMovementState>
[CustomType(typeof(PlayerCharacterController))]
public class PlayerCharacterController : StateBasedBehavior<IEntityMovementState>
,IEntityMovement
,IPlayerMovement
,IEntityBinaryComponent
@@ -147,7 +148,7 @@ namespace BITFALL.Entities.Player.Movement
[Inject]
private IHealth _health;
[Inject]
private InputActionGroup _inputActionGroup;
internal InputActionGroup inputActionGroup;
[Inject]
private IKnockdown _knockdown;
[Inject]
@@ -191,12 +192,12 @@ namespace BITFALL.Entities.Player.Movement
TransitionState<Walk>();
_inputActionGroup.RegisterCallback(movementAction, OnMovement);
_inputActionGroup.RegisterCallback(viewAction, OnView);
_inputActionGroup.RegisterCallback(jumpAction, OnJump);
_inputActionGroup.RegisterCallback(crouchAction, OnCrouch);
_inputActionGroup.RegisterCallback(runAction, OnRun);
_inputActionGroup.RegisterCallback(crawlAction, OnCrawl);
inputActionGroup.RegisterCallback(movementAction, OnMovement);
inputActionGroup.RegisterCallback(viewAction, OnView);
inputActionGroup.RegisterCallback(jumpAction, OnJump);
inputActionGroup.RegisterCallback(crouchAction, OnCrouch);
inputActionGroup.RegisterCallback(runAction, OnRun);
inputActionGroup.RegisterCallback(crawlAction, OnCrawl);
}
private void OnCrawl(InputAction.CallbackContext obj)
@@ -259,7 +260,7 @@ namespace BITFALL.Entities.Player.Movement
{
if (MovementInput.z > 0)
{
if (_inputActionGroup.GetAction(runAction).IsPressed())
if (inputActionGroup.GetAction(runAction).IsPressed())
{
ExpectRun.shouldBe = true;
}
@@ -270,7 +271,7 @@ namespace BITFALL.Entities.Player.Movement
ExpectSprint.Reset();
}
}
else if (MovementInput == default && _inputActionGroup.GetAction(runAction).IsPressed() is false)
else if (MovementInput == default && inputActionGroup.GetAction(runAction).IsPressed() is false)
{
ExpectRun.Reset();
ExpectSprint.Reset();
@@ -279,7 +280,7 @@ namespace BITFALL.Entities.Player.Movement
{
ExpectRun.Reset();
ExpectSprint.Reset();
}else if (MovementInput.z > 0 && _inputActionGroup.GetAction(runAction).IsPressed())
}else if (MovementInput.z > 0 && inputActionGroup.GetAction(runAction).IsPressed())
{
ExpectRun.shouldBe = true;
}
@@ -410,6 +411,7 @@ namespace BITFALL.Entities.Player.Movement
{
{ interaction: PressInteraction, performed: true } => true,
{ interaction: PressInteraction, canceled: true } => false,
_ when CurrentState is EdgeClimb => false,
_ => RequestClimb
};

View File

@@ -1,4 +1,5 @@
using BITFALL.Player.Movement;
using BITKit;
using BITKit.Entities;
using BITKit.StateMachine;
using Lightbug.CharacterControllerPro.Core;
@@ -8,13 +9,13 @@ namespace BITFALL.Entities.Player.Movement.States
{
public abstract class PlayerCharacterState : IEntityMovementState
{
[SerializeField] protected PlayerCharacterController characterController;
[Inject] public PlayerCharacterController self;
[SerializeField] protected CharacterActor actor;
private IEntityMovementState entryState;
public bool Enabled { get; set; }
public virtual void Initialize()
{
characterController.UnityEntity.Inject(this);
}
public virtual void OnStateEntry(IState old)
@@ -53,24 +54,24 @@ namespace BITFALL.Entities.Player.Movement.States
{
if ( entryState is not null)
{
if ( entryState is IPlayerWalkState or IPlayerRunState or IPlayerSprintState && characterController.topBlocked )
if ( entryState is IPlayerWalkState or IPlayerRunState or IPlayerSprintState && self.topBlocked )
{
characterController.TransitionState<Crouch>();
self.TransitionState<Crouch>();
}
else
{
characterController.TransitionState(entryState);
self.TransitionState(entryState);
}
}
else
{
if (characterController.topBlocked)
if (self.topBlocked)
{
characterController.TransitionState<Crouch>();
self.TransitionState<Crouch>();
}
else
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
}
}

View File

@@ -33,29 +33,29 @@ namespace BITFALL.Entities.Player.Movement.States
{
base.OnStateEntry(old);
actor.SetSize(initialSize,CharacterActor.SizeReferenceType.Bottom);
characterController.ReferenceSpeed = initialSpeed;
self.ReferenceSpeed = initialSpeed;
}
public override void BeforeUpdateMovement(float deltaTime)
{
characterController.CurrentCameraPosition.shouldBe = initialCameraPosition;
self.CurrentCameraPosition.shouldBe = initialCameraPosition;
}
public override void AfterUpdateMovement(float deltaTime)
{
if (knockdown.IsKnockdown)
{
characterController.TransitionState<Knockdown>();
self.TransitionState<Knockdown>();
}
if (knockdown.IsKnockdown is false && characterController.ExpectParachute.shouldBe)
if (knockdown.IsKnockdown is false && self.ExpectParachute.shouldBe)
{
characterController.TransitionState<Parachute>();
characterController.ExpectParachute.Reset();
self.TransitionState<Parachute>();
self.ExpectParachute.Reset();
}
if (characterController.RequestClimb is false) return;
if(characterController.topBlocked)return;
if (self.RequestClimb is false) return;
if(self.topBlocked)return;
// if (characterController.topBlocked is false && characterController.RequestClimb &&
// characterController.climbClosePoint.TryGetClosePoint(out var closePoint))
@@ -65,37 +65,37 @@ namespace BITFALL.Entities.Player.Movement.States
// return;
// }
if (characterController.vaultPoint.TryGetClosePoint(out var closePoint))
if (self.vaultPoint.TryGetClosePoint(out var closePoint))
{
characterController.ExpectClimb.shouldBe = closePoint;
characterController.TransitionState<Vault>();
characterController.ExpectJump.Reset();
characterController.RequestClimb = false;
self.ExpectClimb.shouldBe = closePoint;
self.TransitionState<Vault>();
self.ExpectJump.Reset();
self.RequestClimb = false;
return;
}
if (characterController.climbClosePoint.TryGetClosePoint(out closePoint))
if (self.climbClosePoint.TryGetClosePoint(out closePoint))
{
characterController.ExpectClimb.shouldBe = closePoint;
characterController.TransitionState<Climb>();
characterController.ExpectJump.Reset();
characterController.RequestClimb = false;
self.ExpectClimb.shouldBe = closePoint;
self.TransitionState<Climb>();
self.ExpectJump.Reset();
self.RequestClimb = false;
return;
}
if (characterController.edgeClimbPoint.TryGetClosePoint(out closePoint))
if (self.edgeClimbPoint.TryGetClosePoint(out closePoint))
{
characterController.ExpectClimb.shouldBe = closePoint;
characterController.TransitionState<EdgeClimb>();characterController.ExpectJump.Reset();
characterController.RequestClimb = false;
self.ExpectClimb.shouldBe = closePoint;
self.TransitionState<EdgeClimb>();self.ExpectJump.Reset();
self.RequestClimb = false;
return;
}
}
public override void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
{
var rotation = Quaternion.Euler(0, characterController.LookInput.y, 0);
var movementInput = characterController.MovementInput;
var rotation = Quaternion.Euler(0, self.LookInput.y, 0);
var movementInput = self.MovementInput;
if (_cameraService?.IsCameraActivated is false)
{
@@ -103,7 +103,7 @@ namespace BITFALL.Entities.Player.Movement.States
}
var moveVelocity = rotation * new Vector3(
movementInput.x * Mathf.Min(characterController.initialSpeed, initialSpeed),
movementInput.x * Mathf.Min(self.initialSpeed, initialSpeed),
0,
movementInput.z * initialSpeed
);
@@ -112,18 +112,18 @@ namespace BITFALL.Entities.Player.Movement.States
moveVelocity = rotation * movementInput * initialSpeed;
}
if (characterController.limitSpeed.Allow)
if (self.limitSpeed.Allow)
{
switch (characterController.CurrentState)
switch (self.CurrentState)
{
case IPlayerWalkState:
case IPlayerCrouchState:
moveVelocity = Vector3.ClampMagnitude(moveVelocity, characterController.limitSpeed.Value);
moveVelocity = Vector3.ClampMagnitude(moveVelocity, self.limitSpeed.Value);
break;
}
}
if (characterController.IsGrounded)
if (self.IsGrounded)
{
var effectiveGroundNormal = actor.GroundStableNormal;
@@ -139,7 +139,7 @@ namespace BITFALL.Entities.Player.Movement.States
Vector3.Lerp(currentVelocity, targetMovementVelocity, 1f - Mathf.Exp(-16 * deltaTime));
currentVelocity = newVelocity;
if (characterController.ExpectJump.shouldBe)
if (self.ExpectJump.shouldBe)
{
actor.ForceNotGrounded();
@@ -151,14 +151,14 @@ namespace BITFALL.Entities.Player.Movement.States
currentVelocity.y+= initialJumpForce;
characterController.ExpectJump.Reset();
self.ExpectJump.Reset();
characterController.ExecuteCommand<OnPlayerJumpCommand>();
self.ExecuteCommand<OnPlayerJumpCommand>();
}
}
else
{
if (moveVelocity.sqrMagnitude > 0f && characterController.landFreeze.AllowUpdateWithoutReset)
if (moveVelocity.sqrMagnitude > 0f && self.landFreeze.AllowUpdateWithoutReset)
{
var addedVelocity = moveVelocity * (3 * deltaTime);
@@ -212,7 +212,7 @@ namespace BITFALL.Entities.Player.Movement.States
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
{
var newRotation = Quaternion.Euler(0, characterController.LookInput.y, 0);
var newRotation = Quaternion.Euler(0, self.LookInput.y, 0);
@@ -221,36 +221,36 @@ namespace BITFALL.Entities.Player.Movement.States
if (Physics.Raycast(_cameraService.CameraPosition, _cameraService.CameraRotation * Vector3.forward,
out var hit, 256, LayerMask.GetMask("Default"), QueryTriggerInteraction.Ignore))
{
characterController.ViewForward = (hit.point - (characterController.Position +
characterController.Rotation *
characterController.ViewCenter)).normalized;
self.ViewForward = (hit.point - (self.Position +
self.Rotation *
self.ViewCenter)).normalized;
newRotation = Quaternion.LookRotation(characterController.ViewForward);
characterController.ViewRotation = newRotation;
newRotation = Quaternion.LookRotation(self.ViewForward);
self.ViewRotation = newRotation;
characterController.FocusPoint = hit.point;
self.FocusPoint = hit.point;
Debug.DrawLine(_cameraService.CameraPosition, hit.point, Color.green, 0.1f);
Debug.DrawLine(characterController.Position + characterController.ViewCenter,
characterController.Position +
characterController.ViewCenter + characterController.ViewRotation * Vector3.forward
Debug.DrawLine(self.Position + self.ViewCenter,
self.Position +
self.ViewCenter + self.ViewRotation * Vector3.forward
, Color.blue, 0.1f);
}
else
{
characterController.ViewRotation = Quaternion.Euler(characterController.LookInput);;
self.ViewRotation = Quaternion.Euler(self.LookInput);;
characterController.FocusPoint = characterController.Position +
characterController.ViewRotation * Vector3.forward * 256;
self.FocusPoint = self.Position +
self.ViewRotation * Vector3.forward * 256;
Debug.DrawLine(_cameraService.CameraPosition, _cameraService.CameraRotation * Vector3.forward,
Color.red, 0.1f);
}
var rotationDirection = _cameraService.CameraRotation * characterController.MovementInput;
var rotationDirection = _cameraService.CameraRotation * self.MovementInput;
rotationDirection = Vector3.ProjectOnPlane(rotationDirection, Vector3.up);
if (rotationDirection.sqrMagnitude >= 0.16f)
{
@@ -258,7 +258,7 @@ namespace BITFALL.Entities.Player.Movement.States
currentRotation = Quaternion.Lerp(currentRotation, newPlayerRotation, 1f - Mathf.Exp(-16 * deltaTime));
}
if (characterController.allowFocus)
if (self.allowFocus)
{
currentRotation =
Quaternion.LookRotation(_cameraService.CameraRotation * Vector3.forward, Vector3.up);
@@ -279,16 +279,16 @@ namespace BITFALL.Entities.Player.Movement.States
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
if (characterController.CurrentState != this) return;
switch (characterController.ExpectRun.shouldBe, characterController.ExpectCrouch.shouldBe)
if (self.CurrentState != this) return;
switch (self.ExpectRun.shouldBe, self.ExpectCrouch.shouldBe)
{
case (_,_) when characterController.topBlocked && characterController.IsGrounded:
case (_,_) when self.topBlocked && self.IsGrounded:
case (_, true):
characterController.TransitionState<Crouch>();
self.TransitionState<Crouch>();
return;
case (true, false) when characterController.pauseRun.Allow is false &&
characterController.MovementInput.z > 0:
characterController.TransitionState<Run>();
case (true, false) when self.pauseRun.Allow is false &&
self.MovementInput.z > 0:
self.TransitionState<Run>();
return;
}
}
@@ -300,17 +300,17 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
_equipService.AllowEquip.AddDisableElements(this);
characterController.LimitViewAngle = 20;
self.LimitViewAngle = 20;
base.OnStateEntry(old);
}
public override void AfterUpdateMovement(float deltaTime)
{
if (actor.IsGrounded is false)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
@@ -323,7 +323,7 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
characterController.LimitViewAngle = 0;
self.LimitViewAngle = 0;
_equipService.AllowEquip.RemoveDisableElements(this);
}
}
@@ -338,7 +338,7 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
characterController.InvokeOpenParachute();
self.InvokeOpenParachute();
_equipService.AllowEquip.AddDisableElements(this);
var velocity = actor.Velocity;
@@ -349,20 +349,20 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
characterController.InvokeCloseParachute();
self.InvokeCloseParachute();
_equipService.AllowEquip.RemoveDisableElements(this);
}
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
{
currentRotation = Quaternion.Euler(0,characterController.LookInput.y,0);
currentRotation = Quaternion.Euler(0,self.LookInput.y,0);
}
public override void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
{
var rotation = Quaternion.Euler(0,characterController.LookInput.y,0);
var moveVelocity = rotation * characterController.MovementInput;
var rotation = Quaternion.Euler(0,self.LookInput.y,0);
var moveVelocity = rotation * self.MovementInput;
currentVelocity.y =
Mathf.MoveTowards(
currentVelocity.y,
@@ -377,10 +377,10 @@ namespace BITFALL.Entities.Player.Movement.States
{
if (actor.IsGrounded)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
characterController.ExpectParachute.Reset();
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.ExpectParachute.Reset();
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
}
[Serializable]
@@ -388,12 +388,12 @@ namespace BITFALL.Entities.Player.Movement.States
{
public override void OnStateEntry(IState old)
{
characterController.ExpectRun.being = true;
self.ExpectRun.being = true;
}
public override void OnStateExit(IState old, IState newState)
{
characterController.ExpectRun.being = false;
self.ExpectRun.being = false;
}
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
@@ -407,7 +407,7 @@ namespace BITFALL.Entities.Player.Movement.States
var baseRotation = Quaternion.identity;
base.UpdateRotation(ref baseRotation, deltaTime);
var targetRotation = Quaternion.LookRotation(baseRotation * characterController.MovementInput);
var targetRotation = Quaternion.LookRotation(baseRotation * self.MovementInput);
float maxAngleDelta = 30; // 你可以根据需要调整最大角度差值
float maxDeltaMagnitude = Mathf.Sin(Mathf.Deg2Rad * maxAngleDelta / 2);
@@ -431,52 +431,52 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateUpdate(float deltaTime)
{
base.OnStateUpdate(deltaTime);
AudioSensorService.MakeNoise(actor.Position,characterController.transform,3,new MovementNoise());
AudioSensorService.MakeNoise(actor.Position,self.transform,3,new MovementNoise());
}
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
switch (characterController.CurrentState)
switch (self.CurrentState)
{
case Walk:
case Run:
case Sprint:
case Crouch:
switch (characterController.ExpectRun.shouldBe, characterController.ExpectCrouch.shouldBe)
switch (self.ExpectRun.shouldBe, self.ExpectCrouch.shouldBe)
{
case (_, true):
characterController.TransitionState<Crouch>();
self.TransitionState<Crouch>();
return;
case (false, false):
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
if (_cameraService.IsCameraActivated)
{
if (characterController.MovementInput.z <= 0)
if (self.MovementInput.z <= 0)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
}
else
{
if (characterController.MovementInput == default)
if (self.MovementInput == default)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
}
if (characterController.pauseRun.Allow)
if (self.pauseRun.Allow)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
if (characterController.ExpectSprint.shouldBe && characterController.MovementInput.z > 0)
if (self.ExpectSprint.shouldBe && self.MovementInput.z > 0)
{
characterController.TransitionState<Sprint>();
self.TransitionState<Sprint>();
return;
}
break;
@@ -488,7 +488,7 @@ namespace BITFALL.Entities.Player.Movement.States
if (Enabled is false) return;
if (command is PlayerCancelRunCommand)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
}
}
@@ -505,9 +505,9 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
characterController.ExpectCrouch.being = true;
characterController.ExpectCrouch.shouldBe = true;
characterController.ExecuteCommand<PlayerCancelRunCommand>();
self.ExpectCrouch.being = true;
self.ExpectCrouch.shouldBe = true;
self.ExecuteCommand<PlayerCancelRunCommand>();
_addedVelocity = false;
}
@@ -532,21 +532,21 @@ namespace BITFALL.Entities.Player.Movement.States
}
public override void AfterUpdateMovement(float deltaTime)
{
if (characterController.ExpectRun.shouldBe)
if (self.ExpectRun.shouldBe)
{
characterController.TransitionState<Run>();
self.TransitionState<Run>();
return;
}
if (characterController.ExpectCrouch.shouldBe is false || (alwaysSlide is false && actor.IsGrounded is false))
if (self.ExpectCrouch.shouldBe is false || (alwaysSlide is false && actor.IsGrounded is false))
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
if (actor.Velocity.sqrMagnitude <= stopSpeed)
{
characterController.TransitionState<Crouch>();
self.TransitionState<Crouch>();
}
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
}
[Serializable]
@@ -556,35 +556,35 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
characterController.ExpectCrouch.being = true;
self.ExpectCrouch.being = true;
standInterval.Reset();
}
public override void OnStateExit(IState old, IState newState)
{
characterController.ExpectCrouch.being = false;
self.ExpectCrouch.being = false;
}
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
if(characterController.topBlocked)standInterval.Reset();
if(self.topBlocked)standInterval.Reset();
if (characterController.ExpectRun.shouldBe)
if (self.ExpectRun.shouldBe)
{
characterController.TransitionState<Run>();
self.TransitionState<Run>();
return;
}
if (characterController.ExpectCrouch.shouldBe is false)
if (self.ExpectCrouch.shouldBe is false)
{
if (characterController.topBlocked)
if (self.topBlocked)
{
}
else if(standInterval.AllowUpdateWithoutReset)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
return;
}
@@ -597,11 +597,11 @@ namespace BITFALL.Entities.Player.Movement.States
[SerializeField] private int staminaCost = 1;
public override void OnStateEntry(IState old)
{
characterController.ExpectSprint.being = true;
self.ExpectSprint.being = true;
}
public override void OnStateExit(IState old, IState newState)
{
characterController.ExpectSprint.being = false;
self.ExpectSprint.being = false;
}
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
@@ -614,7 +614,7 @@ namespace BITFALL.Entities.Player.Movement.States
var baseRotation = Quaternion.identity;
base.UpdateRotation(ref baseRotation, deltaTime);
var targetRotation = Quaternion.LookRotation(baseRotation * characterController.MovementInput);
var targetRotation = Quaternion.LookRotation(baseRotation * self.MovementInput);
float maxAngleDelta = 30; // 你可以根据需要调整最大角度差值
float maxDeltaMagnitude = Mathf.Sin(Mathf.Deg2Rad * maxAngleDelta / 2);
@@ -636,35 +636,35 @@ namespace BITFALL.Entities.Player.Movement.States
}
public override void OnStateUpdate(float deltaTime)
{
if (actor.IsGrounded && actor.Velocity.GetLength() > characterController.initialSpeed/2)
characterController.Stamina -= staminaCost * deltaTime;
AudioSensorService.MakeNoise(actor.Position,characterController.transform);
if (actor.IsGrounded && actor.Velocity.GetLength() > self.initialSpeed/2)
self.Stamina -= staminaCost * deltaTime;
AudioSensorService.MakeNoise(actor.Position,self.transform);
}
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
if (Enabled is false) return;
if (characterController.pauseRun.Allow)
if (self.pauseRun.Allow)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
switch (characterController.ExpectRun.shouldBe,characterController.ExpectCrouch.shouldBe)
switch (self.ExpectRun.shouldBe,self.ExpectCrouch.shouldBe)
{
case (_,_) when characterController.Stamina is 0:
characterController.ExpectSprint.Reset();
characterController.TransitionState<Run>();
case (_,_) when self.Stamina is 0:
self.ExpectSprint.Reset();
self.TransitionState<Run>();
return;
case (_,true) when characterController.IsGrounded && characterController.Stamina > 0:
characterController.Stamina -= slideCost;
characterController.TransitionState<Slide>();
case (_,true) when self.IsGrounded && self.Stamina > 0:
self.Stamina -= slideCost;
self.TransitionState<Slide>();
return;
case (_,true):
characterController.TransitionState<Crouch>();
self.TransitionState<Crouch>();
return;
case (true,false) when characterController.MovementInput.z <=0:
case (true,false) when self.MovementInput.z <=0:
case (false,false):
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
return;
}
}
@@ -672,7 +672,7 @@ namespace BITFALL.Entities.Player.Movement.States
{
if (Enabled is false) return;
if(command is PlayerCancelRunCommand)
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
}
@@ -708,16 +708,16 @@ namespace BITFALL.Entities.Player.Movement.States
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
private void OnRevive()
{
if(Enabled)characterController.TransitionState<Walk>();
if(Enabled)self.TransitionState<Walk>();
}
private void OnKnockdown()
{
characterController.TransitionState<Knockdown>();
self.TransitionState<Knockdown>();
}
}
[Serializable]
@@ -745,7 +745,7 @@ namespace BITFALL.Entities.Player.Movement.States
_clipAction = _ClipAction;
characterController.destroyCancellationToken.Register(() =>
self.destroyCancellationToken.Register(() =>
{
Data.RemoveListender<bool>(clipEnv.Value, OnClip);
});
@@ -763,11 +763,11 @@ namespace BITFALL.Entities.Player.Movement.States
if(_health.IsAlive is false) return;
if (obj && Enabled is false)
{
characterController.TransitionState<Clip>();
self.TransitionState<Clip>();
//BIT4Log.Log<Clip>("NoClip Enabled");
}else if (Enabled && obj is false)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
//BIT4Log.Log<Clip>("NoClip Disabled");
}
}
@@ -776,7 +776,7 @@ namespace BITFALL.Entities.Player.Movement.States
{
if (Enabled && obj is false)
{
characterController.TransitionState<Walk>();
self.TransitionState<Walk>();
}
}
@@ -798,12 +798,12 @@ namespace BITFALL.Entities.Player.Movement.States
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
actor.Position += characterController.ViewRotation * characterController.MovementInput * (
deltaTime * (_inputActionGroup.GetAction(characterController.RunAction).IsPressed()
actor.Position += self.ViewRotation * self.MovementInput * (
deltaTime * (_inputActionGroup.GetAction(self.RunAction).IsPressed()
? 8
: characterController.initialSpeed
: self.initialSpeed
));
actor.Rotation = Quaternion.Euler(0,characterController.LookInput.y,0);
actor.Rotation = Quaternion.Euler(0,self.LookInput.y,0);
}
}
}

View File

@@ -55,7 +55,7 @@ namespace BITFALL.Entities.Player.Movement.States
_normalizedTime = 0;
_manualUpdate = false;
characterController.LimitViewAngle = 45;
self.LimitViewAngle = 45;
actor.ForceNotGrounded();
@@ -73,18 +73,18 @@ namespace BITFALL.Entities.Player.Movement.States
actor.IsKinematic = false;
actor.UseRootMotion = false;
if (characterController.vaultPoint is GetVaultPointFromCollider vaultPoint)
if (self.vaultPoint is GetVaultPointFromCollider vaultPoint)
{
actor.Position = vaultPoint.EndPosition-Vector3.up*0.64f;
}
characterController.LimitViewAngle = 0;
self.LimitViewAngle = 0;
//actor.Velocity = lastVelocity;
//actor.ForceGrounded();
characterController.ExpectJump.Reset();
characterController.RequestClimb = false;
self.ExpectJump.Reset();
self.RequestClimb = false;
_normalizedTime = 0;
_manualUpdate = false;
@@ -132,11 +132,11 @@ namespace BITFALL.Entities.Player.Movement.States
// characterController.ExpectClimb.shouldBe - Vector3.up * 0.64f,
// 4f
// );
var endPos = characterController.ExpectClimb.shouldBe - Vector3.up * 0.64f;
var endPos = self.ExpectClimb.shouldBe - Vector3.up * 0.64f;
var t = entryCurve.Evaluate(_elapsedTime);
actor.Position = Vector3.Lerp(_entryPosition, endPos, t);
break;
case 1 when characterController.vaultPoint is GetVaultPointFromCollider vaultPoint:
case 1 when self.vaultPoint is GetVaultPointFromCollider vaultPoint:
var newPos =
Vector3.Lerp(
vaultPoint.StartPosition,
@@ -165,6 +165,9 @@ namespace BITFALL.Entities.Player.Movement.States
public int Phase { get; set; }
[Inject] private IEquipService _equipService;
private Collider _collider;
private Quaternion rotation;
private Transform _chest;
public bool ManualCancel()
{
if (Enabled is false) return false;
@@ -175,16 +178,42 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
_collider = self.edgeClimbPoint.Collider;
//Debug.DrawRay(actor.Position+Vector3.up,_collider.ClosestPoint(actor.Position)-(actor.Position+Vector3.up),Color.green,8f);
if(_collider.Raycast(new Ray(actor.Position, _collider.ClosestPoint(actor.Position)-actor.Position), out var hit, 8))
{
rotation =Quaternion.LookRotation(hit.normal) * Quaternion.Euler(0,180,0);
}
else
{
rotation = actor.Rotation;
}
_chest = self.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.UpperChest);
actor.alwaysNotGrounded = true;
actor.ColliderComponent.enabled = false;
actor.UseRootMotion = true;
characterController.LimitViewAngle = 45;
self.LimitViewAngle = 45;
Phase = 1;
Phase = 0;
_equipService.AllowEquip.AddDisableElements(this);
self.inputActionGroup.RegisterCallback(self.JumpAction, OnJump);
}
private void OnJump(InputAction.CallbackContext obj)
{
switch (obj)
{
case {interaction:PressInteraction,performed:true}:
Exit();
actor.Velocity += actor.Up * 8 + -actor.Forward*3;
self.RequestClimb = false;
return;
}
}
public override void OnStateExit(IState old, IState newState)
@@ -195,9 +224,11 @@ namespace BITFALL.Entities.Player.Movement.States
actor.ColliderComponent.enabled = true;
actor.UseRootMotion = false;
characterController.LimitViewAngle = 0;
self.LimitViewAngle = 0;
_equipService.AllowEquip.RemoveDisableElements(this);
self.inputActionGroup.UnRegisterCallback(self.JumpAction, OnJump);
}
public override void OnStateUpdate(float deltaTime)
@@ -206,21 +237,29 @@ namespace BITFALL.Entities.Player.Movement.States
switch (Phase)
{
case 1:
var targetPos = characterController.ExpectClimb.shouldBe - Vector3.up * 1.6f;
if(Vector3.Distance(targetPos,
actor.Position)
<=0.16f)
Phase = 2;
if(actor.Position.y >= targetPos.y)
Phase = 2;
//actor.Position = targetPos;
case 0:
var targetPos = self.ExpectClimb.shouldBe - Vector3.up * 1.6f;
targetPos -= self.Rotation * Vector3.forward * 0.35f;
if (actor.Position.y >= targetPos.y)
Phase = 5;
if (Phase is 5)
actor.Position = targetPos;
return;
case 2:
if (Vector3.Distance(
characterController.ExpectClimb.shouldBe,
actor.Position)
<= 0.1f)
case 5:
if (_collider.Raycast(new Ray(_chest.position, actor.Forward), out var _, 1))
{
if (self.InputVector.y > 0)
{
Phase = 8;
return;
}
if(self.InputVector.y<0)
{
Exit();
return;
}
}
else
{
Exit();
}
@@ -234,27 +273,27 @@ namespace BITFALL.Entities.Player.Movement.States
base.UpdateVelocity(ref currentVelocity, deltaTime);
switch (Phase)
{
case 1:
// actor.Position =
// Vector3.Slerp(actor.Position,
// characterController.ExpectClimb.shouldBe - Vector3.up * 1.6f,
// deltaTime
// );
case 0:
var currentPosition = actor.Position;
currentPosition = Vector3.Lerp(
currentPosition,
characterController.ExpectClimb.shouldBe - Vector3.up * 1.6f,3.2f*deltaTime);
self.ExpectClimb.shouldBe - Vector3.up * 1.6f,3.2f*deltaTime);
currentPosition.y = actor.Position.y;
currentPosition.y+=(upVelocity+=deltaTime)*deltaTime;
actor.Position = currentPosition;
break;
}
}
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
{
if (Phase is 0)
{
currentRotation = rotation;
}
}
public override void AfterUpdateMovement(float deltaTime)
{
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
@@ -269,33 +308,33 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
ignore = characterController.climbClosePoint.Collider.transform;
ignore = self.climbClosePoint.Collider.transform;
actor.PhysicsComponent.IgnoreCollision(ignore,true);
base.OnStateEntry(old);
characterController.ExpectCrouch.Reset();
self.ExpectCrouch.Reset();
actor.alwaysNotGrounded = true;
actor.ForceNotGrounded();
actor.ColliderComponent.enabled = false;
cancelInterval.Reset();
needInit = true;
characterController.LimitViewAngle = 80;
self.LimitViewAngle = 80;
}
public override void OnStateUpdate(float deltaTime)
{
var distance = Vector3.Distance(characterController.ExpectClimb.shouldBe,
characterController.transform.position);
var distance = Vector3.Distance(self.ExpectClimb.shouldBe,
self.transform.position);
if (
distance<=0.16f
|| actor.IsStable
distance<=0.1f
|| cancelInterval.AllowUpdate && actor.Velocity.sqrMagnitude<=0.16f
)
{
Exit();
return;
}
if (characterController.Position.y >= characterController.ExpectClimb.shouldBe.y)
var pos = actor.Position;
pos.y = self.ExpectClimb.shouldBe.y;
if (self.Position.y >= self.ExpectClimb.shouldBe.y && Vector3.Distance(pos,self.ExpectClimb.shouldBe)<0.1f)
{
Exit();
}
@@ -305,10 +344,10 @@ namespace BITFALL.Entities.Player.Movement.States
actor.PhysicsComponent.IgnoreCollision(ignore,false);
actor.alwaysNotGrounded = false;
actor.ColliderComponent.enabled = true;
characterController.ExpectJump.Reset();
self.ExpectJump.Reset();
actor.ForceGrounded();
characterController.LimitViewAngle = 0;
self.LimitViewAngle = 0;
//
}
@@ -319,9 +358,9 @@ namespace BITFALL.Entities.Player.Movement.States
currentVelocity.y = 0;
needInit = false;
}
var velocity =(characterController.ExpectClimb.shouldBe - characterController.transform.position)*lerpDelta;
var velocity =(self.ExpectClimb.shouldBe - self.transform.position)*lerpDelta;
velocity += characterController.Rotation * characterController.MovementInput.normalized * 1.0f;
velocity += self.Rotation * self.MovementInput.normalized * 1.0f;
currentVelocity = Vector3.Lerp(currentVelocity,velocity,lerpDelta*deltaTime);
@@ -329,7 +368,7 @@ namespace BITFALL.Entities.Player.Movement.States
public override void AfterUpdateMovement(float deltaTime)
{
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
}
[Serializable]
@@ -350,25 +389,25 @@ namespace BITFALL.Entities.Player.Movement.States
{
base.OnStateEntry(old);
characterController.ExpectCrouch.Reset();
self.ExpectCrouch.Reset();
characterController.ExpectJump.Reset();
self.ExpectJump.Reset();
actor.ForceNotGrounded();
actor.RigidbodyComponent.IsKinematic = true;
actor.ColliderComponent.enabled = false;
Init(characterController.OffMeshLink);
Init(self.OffMeshLink);
characterController.LimitViewAngle = 45;
self.LimitViewAngle = 45;
_equipService.AllowEquip.AddDisableElements(this);
exitInterval.Reset();
_inputActionGroup.RegisterCallback(characterController.CrouchAction, OnCrouch);
_inputActionGroup.RegisterCallback(characterController.JumpAction, OnJump);
_inputActionGroup.RegisterCallback(self.CrouchAction, OnCrouch);
_inputActionGroup.RegisterCallback(self.JumpAction, OnJump);
}
private void OnJump(InputAction.CallbackContext obj)
@@ -396,12 +435,12 @@ namespace BITFALL.Entities.Player.Movement.States
actor.RigidbodyComponent.IsKinematic = false;
actor.ColliderComponent.enabled = true;
characterController.LimitViewAngle = 0;
self.LimitViewAngle = 0;
_equipService.AllowEquip.RemoveDisableElements(this);
_inputActionGroup.UnRegisterCallback(characterController.CrouchAction, OnCrouch);
_inputActionGroup.UnRegisterCallback(characterController.JumpAction, OnJump);
_inputActionGroup.UnRegisterCallback(self.CrouchAction, OnCrouch);
_inputActionGroup.UnRegisterCallback(self.JumpAction, OnJump);
}
private void Init(OffMeshLink offMeshLink)
@@ -461,7 +500,7 @@ namespace BITFALL.Entities.Player.Movement.States
var positionA = _offMeshLink.startTransform.position;
var positionB = positionA;
positionB.y = _offMeshLink.endTransform.position.y;
var positionC = actor.Position + Vector3.up * (characterController.MovementInput.z * deltaTime * 1.6f);
var positionC = actor.Position + Vector3.up * (self.MovementInput.z * deltaTime * 1.6f);
Vector3 vectorAC = positionC - positionA;
Vector3 vectorAB = positionB - positionA;
@@ -471,7 +510,7 @@ namespace BITFALL.Entities.Player.Movement.States
actor.Position = closestPoint;
//currentVelocity = Vector3.Lerp(currentVelocity , (closestPoint - actor.Position) , 5 * deltaTime);
characterController.UnityEntity.SetDirect(BITHash.Player.ActionSpeed,characterController.MovementInput.z);
self.UnityEntity.SetDirect(BITHash.Player.ActionSpeed,self.MovementInput.z);
break;
case not null:
@@ -520,10 +559,10 @@ namespace BITFALL.Entities.Player.Movement.States
}
public override void AfterUpdateMovement(float deltaTime)
{
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
}
}
[Serializable]
public sealed class Dodge : PlayerCharacterState,IPlayerDodgeState
{
@@ -545,9 +584,9 @@ namespace BITFALL.Entities.Player.Movement.States
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
direction = characterController.MovementInput.x > 0 ? 1 : -1;
direction = self.MovementInput.x > 0 ? 1 : -1;
process = 0;
characterController.Stamina-= costStamina;
self.Stamina-= costStamina;
actor.UseRootMotion = true;
@@ -581,9 +620,9 @@ namespace BITFALL.Entities.Player.Movement.States
private int OnDamageFactory(DamageMessage msg, int currentDamage)
{
if (characterController.CurrentState is not IPlayerDodgeState || msg.Initiator is not Entity initiator)
if (self.CurrentState is not IPlayerDodgeState || msg.Initiator is not Entity initiator)
return currentDamage;
var _direction = characterController.Position - initiator.transform.position;
var _direction = self.Position - initiator.transform.position;
var verticalAngle = Vector3.Angle(initiator.transform.forward, _direction) - 90.0f;
//Debug.Log(verticalAngle);
return 0;
@@ -626,8 +665,8 @@ namespace BITFALL.Entities.Player.Movement.States
actor.PhysicsComponent.enabled = false;
actor.alwaysNotGrounded = true;
actor.constraintRotation = false;
characterController.ExpectCrouch.Reset();
characterController.LimitViewAngle = 100;
self.ExpectCrouch.Reset();
self.LimitViewAngle = 100;
_equipService.AllowEquip.AddDisableElements(this);
@@ -644,7 +683,7 @@ namespace BITFALL.Entities.Player.Movement.States
actor.PhysicsComponent.enabled = true;
actor.constraintRotation = true;
//actor.enabled = true;
characterController.LimitViewAngle = 0;
self.LimitViewAngle = 0;
_equipService.AllowEquip.RemoveDisableElements(this);
}
@@ -661,10 +700,10 @@ namespace BITFALL.Entities.Player.Movement.States
public override void AfterUpdateMovement(float deltaTime)
{
base.AfterUpdateMovement(deltaTime);
characterController.CurrentCameraPosition.shouldBe = characterController.FpvLocalPosition;
if (characterController.ExpectCrouch.shouldBe && _fixedPlace.Exit(characterController.Entity))
self.CurrentCameraPosition.shouldBe = self.FpvLocalPosition;
if (self.ExpectCrouch.shouldBe && _fixedPlace.Exit(self.Entity))
{
characterController.ExpectCrouch.Reset();
self.ExpectCrouch.Reset();
Exit();
}else if (_fixedPlace is null)
{
@@ -676,14 +715,14 @@ namespace BITFALL.Entities.Player.Movement.States
if (obj is not MonoBehaviour monoBehaviour ||
monoBehaviour.TryGetComponent<IPlayerFixedPlace>(out var fixedPlace) is false) return;
if (_knockdown.IsKnockdown) return;
if (_fixedPlace?.Exit(characterController.Entity) is false)
if (_fixedPlace?.Exit(self.Entity) is false)
{
return;
}
if (fixedPlace.Entry(characterController.Entity))
if (fixedPlace.Entry(self.Entity))
{
_fixedPlace = fixedPlace;
characterController.TransitionState<Fixed>();
self.TransitionState<Fixed>();
return;
}
_fixedPlace = null;
@@ -696,7 +735,7 @@ namespace BITFALL.Entities.Player.Movement.States
var rotation = Quaternion.Inverse(_fixedPlace.FixedRotation) * lastRotation;
var euler =MathV.TransientRotationAxis(rotation.eulerAngles);
var add = new float2(euler.x, -euler.y);
characterController.AddViewEuler(add);
self.AddViewEuler(add);
lastRotation = _fixedPlace.FixedRotation;
}
protected override void Exit()
@@ -709,5 +748,11 @@ namespace BITFALL.Entities.Player.Movement.States
_fixedPlace = null;
}
}
[Serializable]
public sealed class ClimbBar
{
}
}