1
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Security.Permissions;
|
||||
using System.Timers;
|
||||
using BITFALL.Entities.Player.Movement.States;
|
||||
using BITFALL.Player.Equip;
|
||||
using BITFALL.Player.Movement;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
@@ -22,18 +23,29 @@ namespace BITFALL.Entities.Player.Movement
|
||||
[CustomType(typeof(IPlayerMovement))]
|
||||
public class PlayerCharacterController : StateBasedPlayerBehavior<IEntityMovementState>,IEntityMovement,IPlayerMovement
|
||||
{
|
||||
[SerializeField] private CharacterActor actor;
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] private Vector3 initialCameraPosition = new(0,0.11f,0.27f);
|
||||
[SerializeField] private float initialSpeed;
|
||||
|
||||
[SerializeReference,SubclassSelector] private IClosePoint climbClosePoint;
|
||||
|
||||
[SerializeReference, SubclassSelector]
|
||||
private IProvider adsProvider;
|
||||
|
||||
[Header(Constant.Header.Components)]
|
||||
[SerializeField] private CharacterActor actor;
|
||||
[SerializeField] private LocationAdditive locationAdditive;
|
||||
|
||||
[Header(Constant.Header.Gameobjects)]
|
||||
[SerializeField] private Transform fpvPoint;
|
||||
[SerializeField] private Transform parachuteModel;
|
||||
|
||||
[Header(Constant.Header.Input)]
|
||||
[SerializeField] private InputActionReference movementAction;
|
||||
[SerializeField] private InputActionReference viewAction;
|
||||
[SerializeField] private InputActionReference jumpAction;
|
||||
[SerializeField] private InputActionReference crouchAction;
|
||||
[SerializeField] private InputActionReference runAction;
|
||||
|
||||
[Header(Constant.Header.Providers)]
|
||||
[SerializeReference,SubclassSelector] private IClosePoint climbClosePoint;
|
||||
[SerializeReference, SubclassSelector] private IProvider adsProvider;
|
||||
|
||||
|
||||
public Vector3 Position
|
||||
{
|
||||
@@ -67,30 +79,35 @@ namespace BITFALL.Entities.Player.Movement
|
||||
public ExpectState<Vector3> CurrentCameraPosition;
|
||||
public OffMeshLink OffMeshLink { get; private set; }
|
||||
|
||||
[Header(Constant.Header.Gameobjects)]
|
||||
[SerializeField] private Transform parachuteModel;
|
||||
|
||||
private readonly ValidHandle allowMovement = new();
|
||||
private readonly ValidHandle allowRun = new();
|
||||
[Inject]
|
||||
private IEntityPhysics physics;
|
||||
[Inject]
|
||||
private IHealth _health;
|
||||
internal readonly ValidHandle allowMovement = new();
|
||||
internal readonly ValidHandle allowRun = new();
|
||||
internal readonly ValidHandle pauseRun = new();
|
||||
|
||||
private bool isDead;
|
||||
private Vector3 keepVelocity;
|
||||
private readonly DoubleBuffer<Vector3> gravityDamage = new();
|
||||
private readonly DoubleBuffer<float> gravityDamping = new();
|
||||
private Vector3 cacheGravity;
|
||||
|
||||
[Inject]
|
||||
private IEntityPhysics _physics;
|
||||
[Inject]
|
||||
private IHealth _health;
|
||||
[Inject]
|
||||
private InputActionGroup _inputActionGroup;
|
||||
|
||||
|
||||
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
physics.OnSetPhysics += OnSetPhysics;
|
||||
_physics.OnSetPhysics += OnSetPhysics;
|
||||
LookInput = MathV.TransientRotationAxis(transform.rotation.eulerAngles);
|
||||
|
||||
parachuteModel.gameObject.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
@@ -101,11 +118,19 @@ namespace BITFALL.Entities.Player.Movement
|
||||
actor.PhysicsComponent.IgnoreCollision(x.transform,true);
|
||||
}
|
||||
TransitionState<Walk>();
|
||||
|
||||
|
||||
_inputActionGroup.RegisterCallback(movementAction, Movement);
|
||||
_inputActionGroup.RegisterCallback(viewAction, View);
|
||||
_inputActionGroup.RegisterCallback(jumpAction, Jump);
|
||||
_inputActionGroup.RegisterCallback(crouchAction, Crouch);
|
||||
_inputActionGroup.RegisterCallback(runAction, Run);
|
||||
}
|
||||
private void OnSetPhysics(bool obj)
|
||||
{
|
||||
if (obj is false) return;
|
||||
physics.Velocity = keepVelocity;
|
||||
//_physics.Velocity = keepVelocity;
|
||||
_physics.Velocity = default;
|
||||
actor.Velocity = Vector3.zero;
|
||||
}
|
||||
|
||||
@@ -116,7 +141,7 @@ namespace BITFALL.Entities.Player.Movement
|
||||
if (obj)
|
||||
{
|
||||
if (!isDead) return;
|
||||
actor.Position = physics.Center;
|
||||
actor.Position = _physics.Center;
|
||||
isDead = false;
|
||||
}
|
||||
else
|
||||
@@ -159,12 +184,19 @@ namespace BITFALL.Entities.Player.Movement
|
||||
case PlayerDisableRunCommand disableRunCommand:
|
||||
allowRun.AddDisableElements(disableRunCommand.Lock);
|
||||
break;
|
||||
case PlayerCancelRunCommand:
|
||||
ExpectRun.Reset();
|
||||
ExpectSprint.Reset();
|
||||
break;
|
||||
case PlayerChangeVelocityCommand changeVelocityCommand:
|
||||
actor.Velocity = Vector3.Lerp(actor.Velocity, changeVelocityCommand.Velocity, 5 * Time.deltaTime);
|
||||
break;
|
||||
case PlayerAddGravityDampingCommand addGravityDampingCommand:
|
||||
gravityDamping.Release(addGravityDampingCommand.Damping);
|
||||
break;
|
||||
case PlayerPauseRunCommand pauseRunCommand:
|
||||
pauseRun.SetElements(this,pauseRunCommand.Pause);
|
||||
break;
|
||||
}
|
||||
OnCommand?.Invoke(command);
|
||||
}
|
||||
@@ -333,8 +365,8 @@ namespace BITFALL.Entities.Player.Movement
|
||||
{
|
||||
actor.Velocity = currentVelocity;
|
||||
actor.Rotation = currentRotation;
|
||||
if (currentVelocity.sqrMagnitude > 0.01f)
|
||||
keepVelocity = currentVelocity;
|
||||
//if (currentVelocity.sqrMagnitude > 0.01f)
|
||||
keepVelocity = currentVelocity;
|
||||
}
|
||||
|
||||
var localVelocity = transform.InverseTransformDirection(Velocity);
|
||||
|
Reference in New Issue
Block a user