Merged Wall and Ground Enemies into One
This commit is contained in:
@@ -31,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");
|
||||
|
@@ -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)
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: adfb41bcf8c09e94ea1e95e22a4c7533
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -7,10 +7,10 @@ namespace Player
|
||||
{
|
||||
public class PlayerController : MonoBehaviour, IMovement, Input.PlayerInput.IPlayerControlActions
|
||||
{
|
||||
private const float DefaultJumpForce = 1200.0f;
|
||||
private const float DefaultJumpForce = 784.0f;
|
||||
private const float DefaultMass = 80.0f;
|
||||
private const float DefaultSpeed = 500.0f;
|
||||
private const float GravityScale = 3.0f;
|
||||
private const float GravityScale = 1.0f;
|
||||
|
||||
private Input.PlayerInput _controls;
|
||||
private Rigidbody2D _playerRigidbody2D;
|
||||
@@ -139,4 +139,4 @@ namespace Player
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user