First Commit
This commit is contained in:
54
2D/OneDimensional2DAirMovement.cs
Normal file
54
2D/OneDimensional2DAirMovement.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Syntriax.Modules.Movement.ColliderCheck;
|
||||
using Syntriax.Modules.Movement.ColliderCheck.Ground;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Movement
|
||||
{
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class OneDimensional2DAirMovement : MonoBehaviour, IMovement, IState
|
||||
{
|
||||
private IGroundCheck groundCheck = null;
|
||||
private Rigidbody2D rigid = null;
|
||||
private float moveValue = 0f;
|
||||
|
||||
|
||||
public bool IsActive => StateEnabled && !groundCheck.IsCollided();
|
||||
public bool StateEnabled { get; set; } = true;
|
||||
public float SpeedMultiplier { get; set; } = 1f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rigid = GetComponent<Rigidbody2D>();
|
||||
groundCheck = GetComponentInChildren<IGroundCheck>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
ApplyMovement();
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
public void Move(float x = 0, float y = 0, float z = 0)
|
||||
{
|
||||
moveValue = x * SpeedMultiplier;
|
||||
}
|
||||
}
|
||||
}
|
11
2D/OneDimensional2DAirMovement.cs.meta
Normal file
11
2D/OneDimensional2DAirMovement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12a58daabbf3fa8418a164390a593753
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
44
2D/OneDimensional2DGroundMovement.cs
Normal file
44
2D/OneDimensional2DGroundMovement.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Syntriax.Modules.Movement.ColliderCheck;
|
||||
using Syntriax.Modules.Movement.ColliderCheck.Ground;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Movement
|
||||
{
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class OneDimensional2DGroundMovement : MonoBehaviour, IMovement, IState
|
||||
{
|
||||
private IGroundCheck groundCheck = null;
|
||||
private Rigidbody2D rigid = null;
|
||||
private float moveValue = 0f;
|
||||
|
||||
public bool IsActive => StateEnabled && groundCheck.IsCollided();
|
||||
public bool StateEnabled { get; set; } = true;
|
||||
public float SpeedMultiplier { get; set; } = 1f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rigid = GetComponent<Rigidbody2D>();
|
||||
groundCheck = GetComponentInChildren<IGroundCheck>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
ApplyMovement();
|
||||
}
|
||||
|
||||
private void ApplyMovement()
|
||||
{
|
||||
Vector2 velocity = rigid.velocity;
|
||||
velocity.x = moveValue;
|
||||
rigid.velocity = velocity;
|
||||
}
|
||||
|
||||
public void Move(float x = 0, float y = 0, float z = 0)
|
||||
{
|
||||
moveValue = x * SpeedMultiplier;
|
||||
}
|
||||
}
|
||||
}
|
11
2D/OneDimensional2DGroundMovement.cs.meta
Normal file
11
2D/OneDimensional2DGroundMovement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 849a6316df6662a48ae6cfcd4c2fbc1e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user