Updated wait for start logic

This commit is contained in:
2026-06-19 15:03:15 +02:00
parent 420bef5862
commit b3d6ebaf67

View File

@@ -22,7 +22,8 @@ namespace Marro.PacManUdon
Returning, Returning,
Entering, Entering,
Home, Home,
Exiting Exiting,
WaitingForStart,
} }
public enum PacManGhostStartState public enum PacManGhostStartState
@@ -122,37 +123,31 @@ namespace Marro.PacManUdon
// Debug.Log($"{gameObject} Reset!"); // Debug.Log($"{gameObject} Reset!");
transform.SetLocalPositionAndRotation(startPosition, startRotation); transform.SetLocalPositionAndRotation(startPosition, startRotation);
if (startState == PacManGhostStartState.Outside) offGrid = true;
{
ghostState = PacManGhostState.Exiting;
OffGridTargetReached();
}
else
{
if (startState == PacManGhostStartState.TargetingIdlePosition1)
{
SetOffGridTarget(idlePosition1, false);
SetTargetDirection(Direction.Down);
}
else
{
SetTargetDirection(Direction.Up);
}
ghostState = PacManGhostState.Entering;
OffGridTargetReached();
}
isScared = false; isScared = false;
inTunnel = false; inTunnel = false;
kinematic = false; kinematic = false;
followingPredefinedPath = false; followingPredefinedPath = false;
turnAroundSoon = false; turnAroundSoon = false;
specialLook = false; specialLook = false;
rngState = 1; rngState = 1;
UpdateSpeed();
UpdateAnimator(); ghostState = PacManGhostState.WaitingForStart;
switch (startState)
{
case PacManGhostStartState.TargetingIdlePosition1:
SetTargetDirection(Direction.Up);
break;
case PacManGhostStartState.TargetingIdlePosition2:
SetTargetDirection(Direction.Down);
break;
default:
SetTargetDirection(Direction.Left);
break;
}
UpdateSpeed();
// Debug.Log($"{gameObject} reset with state: {state}, target: {target}, offGrid: {offGrid}"); // Debug.Log($"{gameObject} reset with state: {state}, target: {target}, offGrid: {offGrid}");
} }
@@ -189,6 +184,25 @@ namespace Marro.PacManUdon
return nextPosition; return nextPosition;
} }
if (ghostState == PacManGhostState.WaitingForStart)
{
switch (startState)
{
case PacManGhostStartState.TargetingIdlePosition1:
SetOffGridTarget(idlePosition1, false);
ghostState = PacManGhostState.Entering;
break;
case PacManGhostStartState.TargetingIdlePosition2:
SetOffGridTarget(idlePosition2, false);
ghostState = PacManGhostState.Entering;
break;
default:
ghostState = PacManGhostState.Exiting;
break;
}
OffGridTargetReached();
}
if (offGrid || ghostState == PacManGhostState.Returning) if (offGrid || ghostState == PacManGhostState.Returning)
{ {
PerformOffgridRelatedMovement(position, ref nextPosition); PerformOffgridRelatedMovement(position, ref nextPosition);
@@ -499,33 +513,33 @@ namespace Marro.PacManUdon
if (!gameObject.activeInHierarchy) if (!gameObject.activeInHierarchy)
return; return;
// Debug.Log($"{gameObject} UpdateAnimator with state: {ghostState}, isScared: {isScared}, direction: {direction}"); if (frozenState == PacManGhostFrozenState.FrozenIfNotCaught) // Looks like a bug but matches the original game
if (specialLook)
{ {
SetAnimatorGhostType((int)PacManGhostType.Special); return;
}
else if (!isScared) // Note: Don't update ghost type while scared as this interrupts the white/blue blinking
{
switch (ghostState)
{
default:
case PacManGhostState.Normal:
case PacManGhostState.Home:
case PacManGhostState.Exiting:
// Debug.Log($"{gameObject} Set GhostType in animator to: {GhostTypeToAnimationValue(ghostType)}");
SetAnimatorGhostType((int)ghostType);
break;
case PacManGhostState.Returning:
case PacManGhostState.Entering:
SetAnimatorGhostType((int)PacManGhostType.Caught);
break;
}
} }
if (specialLook || targetDirection != Direction.Zero) if (specialLook || targetDirection != Direction.Zero)
{ {
SetAnimatorDirection((int)targetDirection); SetAnimatorDirection((int)targetDirection);
} }
if (isScared) // Don't update ghost type while scared as this interrupts the white/blue blinking
{
return;
}
PacManGhostType ghostType = this.ghostType;
if (specialLook)
{
ghostType = PacManGhostType.Special;
}
else if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering)
{
ghostType = PacManGhostType.Caught;
}
SetAnimatorGhostType((int)ghostType);
} }
// A Udon bug means converting an enum to a float causes an exception unless the conversion from int to float is in a separate method // A Udon bug means converting an enum to a float causes an exception unless the conversion from int to float is in a separate method
@@ -672,7 +686,13 @@ namespace Marro.PacManUdon
} }
else else
{ {
var oldFrozenState = frozenState;
frozenState = PacManGhostFrozenState.NotFrozen; frozenState = PacManGhostFrozenState.NotFrozen;
if (oldFrozenState == PacManGhostFrozenState.FrozenIfNotCaught) // Catch animator up after not updating during FrozenIfNotCaught
{
UpdateAnimator();
}
} }
animator.speed = frozen && !keepAnimating ? 0 : 1; // This would cause issues if the returning sprite was animated, luckily it isn't :) animator.speed = frozen && !keepAnimating ? 0 : 1; // This would cause issues if the returning sprite was animated, luckily it isn't :)
} }