2026-05-18 버그 수정
This commit is contained in:
@@ -19,6 +19,12 @@ public class Enemy : MonoBehaviour, IDamageable
|
||||
[SerializeField] private float _wallBounceMinXVelocity = 1f;
|
||||
[SerializeField] private float _wallBounceUpwardVelocity = 1.5f;
|
||||
|
||||
[Header("Separation")]
|
||||
[SerializeField] private float _separationRadius = 0.6f;
|
||||
[SerializeField] private float _separationStrength = 2f;
|
||||
[SerializeField] private LayerMask _separationLayer;
|
||||
private static readonly Collider2D[] _separationBuffer = new Collider2D[16];
|
||||
|
||||
private int _currentHealth;
|
||||
private Rigidbody2D _rb;
|
||||
private Animator _anim;
|
||||
@@ -58,7 +64,10 @@ private void Update()
|
||||
{
|
||||
_flashTimer -= Time.deltaTime;
|
||||
if (_flashTimer <= 0f && _spriteRenderer != null)
|
||||
{
|
||||
Debug.Log($"[Flash END] t={Time.time:F3} → revert to {_originalColor}");
|
||||
_spriteRenderer.color = _originalColor;
|
||||
}
|
||||
}
|
||||
|
||||
if (_hitReactionTimer > 0f)
|
||||
@@ -78,10 +87,60 @@ private void FixedUpdate()
|
||||
}
|
||||
|
||||
ApplySmoothHitPositionCorrection();
|
||||
ApplySeparation();
|
||||
_lastVelocity = _rb.linearVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplySeparation()
|
||||
{
|
||||
if (_separationRadius <= 0f || _separationStrength <= 0f) return;
|
||||
if (_separationLayer.value == 0) return;
|
||||
|
||||
ContactFilter2D filter = new ContactFilter2D
|
||||
{
|
||||
useLayerMask = true,
|
||||
layerMask = _separationLayer,
|
||||
useTriggers = false
|
||||
};
|
||||
|
||||
int count = Physics2D.OverlapCircle(_rb.position, _separationRadius, filter, _separationBuffer);
|
||||
Vector2 push = Vector2.zero;
|
||||
int contributors = 0;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Collider2D other = _separationBuffer[i];
|
||||
if (other == null) continue;
|
||||
if (other.attachedRigidbody == _rb) continue;
|
||||
|
||||
Vector2 away = _rb.position - (Vector2)other.transform.position;
|
||||
float dist = away.magnitude;
|
||||
if (dist >= _separationRadius) continue;
|
||||
|
||||
Vector2 dir;
|
||||
if (dist < 0.001f)
|
||||
{
|
||||
// 완전히 같은 위치인 경우 무작위 수평 방향으로 분리
|
||||
dir = UnityEngine.Random.value < 0.5f ? Vector2.left : Vector2.right;
|
||||
}
|
||||
else
|
||||
{
|
||||
dir = away / dist;
|
||||
}
|
||||
|
||||
float strength = 1f - (dist / _separationRadius);
|
||||
push += dir * strength;
|
||||
contributors++;
|
||||
}
|
||||
|
||||
if (contributors == 0) return;
|
||||
|
||||
push /= contributors;
|
||||
// X축으로만 분리. Y는 중력에 맡겨서 바운스/공중부양 방지.
|
||||
_rb.position += new Vector2(push.x, 0f) * (_separationStrength * Time.fixedDeltaTime);
|
||||
}
|
||||
|
||||
public void TakeDamage(int amount, Vector2 hitVelocity = default, string hitReactionAnimationState = null, Vector2? hitTargetPosition = null, bool correctHitTargetY = false, int hitPositionSolidMask = 0, float hitPositionCorrectionDuration = 0f)
|
||||
{
|
||||
if (_currentHealth <= 0) return;
|
||||
@@ -93,6 +152,7 @@ public void TakeDamage(int amount, Vector2 hitVelocity = default, string hitReac
|
||||
|
||||
if (_spriteRenderer != null)
|
||||
{
|
||||
Debug.Log($"[Flash START] t={Time.time:F3} duration={_hitFlashDuration:F3} (current color was {_spriteRenderer.color})");
|
||||
_spriteRenderer.color = _hitFlashColor;
|
||||
_flashTimer = _hitFlashDuration;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user