41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Syntriax.Modules.Movement.ColliderTrigger;
|
|
using UnityEngine;
|
|
|
|
namespace Syntriax.Modules.Movement
|
|
{
|
|
public class OneWay2DAirMovement : OneWay2DMovementBase
|
|
{
|
|
protected override float moveValue { get; set; } = 0f;
|
|
protected IGroundTrigger groundTrigger = null;
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
|
groundTrigger.OnTriggered.AddListener(OnGroundTrigger);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
protected override void OnDeactivated() { }
|
|
protected override void OnActivated() { }
|
|
}
|
|
}
|