2022-11-14 13:21:35 +03:00
|
|
|
using Syntriax.Modules.Trigger;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-12-17 12:04:14 +03:00
|
|
|
namespace Syntriax.Modules.Movement.Samples
|
2022-11-14 13:21:35 +03:00
|
|
|
{
|
|
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
|
|
public class AirMovement1D : MovementBase1D
|
|
|
|
{
|
|
|
|
protected override float moveValue { get; set; } = 0f;
|
|
|
|
protected IGroundTrigger groundTrigger = null;
|
|
|
|
protected Rigidbody2D rigid = null;
|
|
|
|
|
|
|
|
protected override void Start()
|
|
|
|
{
|
|
|
|
base.Start();
|
|
|
|
|
2023-03-20 22:51:49 +03:00
|
|
|
rigid = GetComponentInParent<Rigidbody2D>();
|
2022-11-14 13:21:35 +03:00
|
|
|
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
2022-11-15 16:26:26 +03:00
|
|
|
|
|
|
|
if (groundTrigger != null)
|
|
|
|
{
|
2022-12-17 11:59:08 +03:00
|
|
|
groundTrigger.OnTriggerStateChanged += OnGroundTrigger;
|
2022-11-15 16:26:26 +03:00
|
|
|
CanTakeOver = false;
|
|
|
|
}
|
2022-11-14 13:21:35 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDeactivated() { }
|
|
|
|
protected override void OnActivated() { }
|
|
|
|
}
|
|
|
|
}
|