Ghost - PacMan collision detection

This commit is contained in:
2026-06-17 14:12:36 +02:00
parent e3b626f3d6
commit a7d1adf175
6 changed files with 302 additions and 127 deletions

View File

@@ -197,15 +197,10 @@ namespace Marro.PacManUdon
TryToTurn(position, ref nextPosition);
}
var distance = Vector2.Distance(position, nextPosition);
if (distance > 0.5f)
{
Debug.LogError($"{gameObject} Just jumped by distance {distance}! position: {position}, nextPosition: {nextPosition}, direction: {direction}, offGrid: {offGrid}, ghostState: {ghostState}");
}
if (CrossesTileBorder(position, nextPosition, direction))
{
var inTunnel = pelletManager.IsInTunnel(nextPosition);
var inTunnel = pelletManager.GhostMoveToTile(nextPosition, Index);
if (inTunnel != this.inTunnel)
{
this.inTunnel = inTunnel;
@@ -595,6 +590,20 @@ namespace Marro.PacManUdon
}
}
internal void HitPacMan()
{
if (isScared)
{
Debug.Log($"{gameObject} was cought!");
ghostManager.GhostCaughtQueue(this);
}
else if (ghostState == PacManGhostState.Normal)
{
Debug.Log($"{gameObject} cought PacMan!");
ghostManager.CapturedPacMan();
}
}
public void Caught(int scoreBonus)
{
isScared = false;
@@ -844,22 +853,5 @@ namespace Marro.PacManUdon
return base.WriteSyncedData(data, ref index, eventType);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<PacManGhostCollider>())
{
if (isScared)
{
// Debug.Log($"{gameObject} was cought!");
ghostManager.GhostCaughtQueue(this);
}
else if (ghostState == PacManGhostState.Normal)
{
// Debug.Log($"{gameObject} cought PacMan!");
ghostManager.CapturedPacMan();
}
}
}
}
}