improv: UnitMovementHandler.cs uses IUnitDirectionProvider.cs for direction instead of input direction directly
This commit is contained in:
@@ -19,7 +19,7 @@ namespace Reset.Units{
|
||||
|
||||
// References
|
||||
private CharacterController controller;
|
||||
private PlayerControls controls;
|
||||
private IUnitDirectionProvider directionProvider;
|
||||
private IUnitTargetProvider targetProvider;
|
||||
|
||||
// Movement Data
|
||||
@@ -30,7 +30,7 @@ namespace Reset.Units{
|
||||
|
||||
void Awake(){
|
||||
controller = GetComponent<CharacterController>();
|
||||
controls = GetComponent<PlayerControls>();
|
||||
directionProvider = GetComponent<IUnitDirectionProvider>();
|
||||
targetProvider = GetComponent<IUnitTargetProvider>();
|
||||
|
||||
InitAllSettings();
|
||||
@@ -59,7 +59,7 @@ namespace Reset.Units{
|
||||
// Update the direction, called every frame
|
||||
private void UpdateCurrentDirection(){
|
||||
// Get input value
|
||||
Vector2 targetDirection = new Vector2(controls.rawMoveInput.x, controls.rawMoveInput.y);
|
||||
Vector2 targetDirection = new Vector2(directionProvider.Direction.x, directionProvider.Direction.y);
|
||||
|
||||
// Rotate input by camera rotation (instead of rotating the output direction by camera rotation)
|
||||
targetDirection = (Camera.main.transform.rotation * targetDirection.ToVector3()).ToVector2();
|
||||
@@ -97,7 +97,7 @@ namespace Reset.Units{
|
||||
newDirection = Vector2.SmoothDamp(currentDirection, targetDirection, ref refVelocityDirectionChangingHardness, data.directionChangingSoftness.Value * data.airDirectionDecay.Value * Time.deltaTime);
|
||||
}
|
||||
|
||||
newDirection = Vector3.Slerp(resolvedMovement.moveDirection.World, newDirection, controls.rawMoveInput.magnitude);
|
||||
newDirection = Vector3.Slerp(resolvedMovement.moveDirection.World, newDirection, directionProvider.Direction.magnitude);
|
||||
|
||||
// Commit the new direction
|
||||
resolvedMovement.moveDirection.World = newDirection;
|
||||
@@ -108,7 +108,7 @@ namespace Reset.Units{
|
||||
// ""Smooth"" the speed
|
||||
float smoothedSpeed;
|
||||
|
||||
if (resolvedMovement.moveDirection.Local.magnitude < controls.rawMoveInput.magnitude) {
|
||||
if (resolvedMovement.moveDirection.Local.magnitude < directionProvider.Direction.magnitude) {
|
||||
smoothedSpeed = Mathf.MoveTowards(resolvedMovement.moveSpeed, data.moveSpeed.Value, data.acceleration.Value * Time.deltaTime);
|
||||
} else {
|
||||
smoothedSpeed = Mathf.MoveTowards(resolvedMovement.moveSpeed, 0f, data.deacceleration.Value * Time.deltaTime);
|
||||
@@ -135,7 +135,7 @@ namespace Reset.Units{
|
||||
// Update the rotation, called every frame
|
||||
private void UpdateCurrentRotation(){
|
||||
// Get input value
|
||||
Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y);
|
||||
Vector3 inputMovement = new Vector3(directionProvider.Direction.x, 0f, directionProvider.Direction.y);
|
||||
|
||||
Quaternion targetRotation = Quaternion.identity;
|
||||
// Switch the desired rotation based on current movement setting
|
||||
@@ -162,7 +162,7 @@ namespace Reset.Units{
|
||||
break;
|
||||
case PlayerFacingDirection.MatchInput:
|
||||
// Look towards the input direction- similar to Momentum but snappier
|
||||
if (controls.rawMoveInput.magnitude < 0.05f) { break; }
|
||||
if (directionProvider.Direction.magnitude < 0.05f) { break; }
|
||||
|
||||
targetRotation = Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement);
|
||||
break;
|
||||
@@ -181,7 +181,7 @@ namespace Reset.Units{
|
||||
// Add the current input into the created rotation
|
||||
if (data.facingDirection.Value == PlayerFacingDirection.MatchCamera || data.facingDirection.Value == PlayerFacingDirection.TowardsTarget) {
|
||||
resolvedMovement.rotation = targetRotation;
|
||||
} else if (controls.rawMoveInput.sqrMagnitude > .1){
|
||||
} else if (directionProvider.Direction.sqrMagnitude > .1){
|
||||
resolvedMovement.rotation = targetRotation;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user