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

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