2022-03-08 10:13:27 +03:00
|
|
|
using Syntriax.Modules.Movement.ColliderTrigger;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-11-13 17:43:30 +03:00
|
|
|
namespace Syntriax.Modules.Movement.Implementations.TwoDimensional
|
2022-03-08 10:13:27 +03:00
|
|
|
{
|
2022-11-13 17:43:30 +03:00
|
|
|
public class OneDirectional2DAirMovement : OneDirectional2DMovementBase
|
2022-03-08 10:13:27 +03:00
|
|
|
{
|
|
|
|
protected override float moveValue { get; set; } = 0f;
|
|
|
|
protected IGroundTrigger groundTrigger = null;
|
|
|
|
|
|
|
|
protected override void Start()
|
|
|
|
{
|
|
|
|
base.Start();
|
|
|
|
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
2022-11-14 12:02:31 +03:00
|
|
|
groundTrigger.OnTriggered += OnGroundTrigger;
|
2022-03-08 10:13:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnGroundTrigger(bool isGrounded)
|
|
|
|
=> CanTakeOver = !isGrounded;
|
|
|
|
|
|
|
|
public override void ApplyMovement()
|
|
|
|
{
|
|
|
|
Vector2 velocity = rigid.velocity;
|
|
|
|
velocity.x += moveValue * Time.fixedDeltaTime;
|
|
|
|
|
|
|
|
if (moveValue != 0f)
|
|
|
|
{
|
|
|
|
if (Mathf.Abs(velocity.x) > Mathf.Abs(moveValue))
|
|
|
|
velocity.x = moveValue;
|
|
|
|
else if (Mathf.Abs(velocity.x - moveValue) > Mathf.Abs(moveValue))
|
|
|
|
velocity.x += moveValue * Time.fixedDeltaTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
rigid.velocity = velocity;
|
|
|
|
}
|
2022-03-13 20:59:45 +03:00
|
|
|
|
|
|
|
protected override void OnDeactivated() { }
|
|
|
|
protected override void OnActivated() { }
|
2022-03-08 10:13:27 +03:00
|
|
|
}
|
|
|
|
}
|