This commit is contained in:
ThomasCharester committed 2026-02-27 14:16:48 +03:00
1 parent 63c3549673
commit 28125eb382
19 files changed
+912 -143

No files matched your search

@@ -0,0 +1,59 @@
using Code.Infrastructure.Configs;
using UnityEngine;
namespace Code.Example.Platformer.Entity.Enemies
{
public class Boar : Entity
{
[SerializeField] private Vector2 groundLeft;
[SerializeField] private Vector2 groundRight;
private bool _directionRight;
private float _acceleration = 3f;
protected override void Move()
{
if (_target)
{
_directionRight = (transform.position - _target.position).magnitude < float.Epsilon;
CheckupDirection();
rigidbody2D.linearVelocityX = _directionRight ? 0.5f : -0.5f;
rigidbody2D.linearVelocity *= _acceleration;
}
else
{
CheckupDirection();
rigidbody2D.linearVelocityX = _directionRight ? 0.5f : -0.5f;
}
}
protected override void HandleFlipX() => spriteRenderer.flipX = rigidbody2D.linearVelocity.x > -0.01f;
private void CheckupDirection()
{
if (_directionRight)
{
if (!Physics2D.OverlapPoint((Vector2)transform.position + groundRight,
LayerMasks.Masks[LayerMaskType.PlatformerGround]))
_directionRight = false;
}
else if (!Physics2D.OverlapPoint((Vector2)transform.position + groundLeft,
LayerMasks.Masks[LayerMaskType.PlatformerGround]))
_directionRight = true;
}
private Transform _target;
public void GotTarget(Transform target)
{
_target = target;
}
public void LostTarget()
{
_target = null;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8a21daf0f518490daeacea92cc2dee2d
timeCreated: 1772187830
@@ -0,0 +1,19 @@
using UnityEngine;
namespace Code.Example.Platformer.Entity.Enemies
{
public class BoarRadar : MonoBehaviour
{
[SerializeField] private Boar boar;
private void OnTriggerEnter2D(Collider2D other)
{
boar.GotTarget(other.transform);
}
private void OnTriggerExit2D(Collider2D other)
{
boar.LostTarget();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e0976ba0c1904671ac17f194f8694aa1
timeCreated: 1772187891