Merge remote-tracking branch 'origin/Syntriax' into Over

# Conflicts:
#	Assets/Scripts/Player/PlayerController.cs
This commit is contained in:
OverflowNarhoym
2022-02-21 22:49:52 +01:00
12 changed files with 525 additions and 254 deletions

View File

@@ -1,9 +1,10 @@
using Movement;
using Pausable;
using UnityEngine;
namespace AI
{
public class BasicPatrollingEnemyAI : MonoBehaviour
public class BasicPatrollingEnemyAI : MonoBehaviour, IPausable
{
[SerializeField] protected bool isMovingRight = false;
@@ -14,6 +15,12 @@ namespace AI
protected CollisionChecker leftGroundChecker = null;
protected CollisionChecker rightGroundChecker = null;
#region IPausable
public bool IsPaused { get; protected set; } = false;
public virtual void Pause() => IsPaused = true;
public virtual void Resume() => IsPaused = false;
#endregion
// If moving Right, and either there's no more ground to move into or there is a wall at the Right side of the enemy OR
// If moving Left, and either there's no more ground to move into or there is a wall at the Left side of the enemy
@@ -24,7 +31,7 @@ namespace AI
protected virtual void Awake()
{
movement = gameObject.GetComponent<EnemyMovement>();
movement = gameObject.AddComponent<EnemyMovement>();
leftWallChecker = GetCollisionCheckerOnChild("Collision Checkers/Left Wall");
rightWallChecker = GetCollisionCheckerOnChild("Collision Checkers/Right Wall");
leftGroundChecker = GetCollisionCheckerOnChild("Collision Checkers/Left Ground");
@@ -33,6 +40,9 @@ namespace AI
protected virtual void FixedUpdate()
{
if (IsPaused)
return;
if (ShouldChangeDirection)
isMovingRight = !isMovingRight;

View File

@@ -6,6 +6,7 @@ namespace Movement
public class EnemyMovement : MonoBehaviour, IMovement
{
protected Rigidbody2D _rigidbody2D = null;
protected Vector2 gravityForce = Vector2.down;
protected bool _isPaused = false;
protected float moveValue = 0f;
@@ -13,16 +14,23 @@ namespace Movement
public bool IsPaused => _isPaused;
protected virtual void Awake()
=> _rigidbody2D = GetComponent<Rigidbody2D>();
{
_rigidbody2D = GetComponent<Rigidbody2D>();
_rigidbody2D.gravityScale = 0f;
gravityForce *= -Physics2D.gravity.y * _rigidbody2D.mass;
}
protected virtual void FixedUpdate()
{
_rigidbody2D.AddRelativeForce(gravityForce);
if (IsPaused)
return;
Vector2 velocity = _rigidbody2D.velocity;
Vector2 velocity = transform.InverseTransformDirection(_rigidbody2D.velocity);
velocity.x = moveValue;
_rigidbody2D.velocity = velocity;
_rigidbody2D.velocity = transform.TransformDirection(velocity);
}
public void Move(float value)

View File

@@ -1,29 +0,0 @@
using UnityEngine;
namespace Movement
{
public class EnemyVerticalMovement : EnemyMovement
{
protected Vector2 gravityForce = Vector2.right;
protected override void Awake()
{
base.Awake();
_rigidbody2D.gravityScale = 0f;
gravityForce *= -Physics2D.gravity.y * _rigidbody2D.mass;
}
protected override void FixedUpdate()
{
_rigidbody2D.AddRelativeForce(gravityForce);
if (IsPaused)
return;
Vector2 velocity = _rigidbody2D.velocity;
velocity.y = moveValue;
_rigidbody2D.velocity = velocity;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: adfb41bcf8c09e94ea1e95e22a4c7533
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: