More Direction
This commit is contained in:
@@ -141,21 +141,23 @@ namespace Marro.PacManUdon
|
||||
Debug.Log($"{gameObject} crossed Y tile center from {position} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
|
||||
}
|
||||
|
||||
Vector2 inputDirection = input.GetDirection();
|
||||
if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction
|
||||
&& (inputDirection.x == 0 || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border
|
||||
&& (inputDirection.y == 0 || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0)
|
||||
&& !CheckCollisionInDirection(transform, nextPosition, inputDirection))
|
||||
var inputDirection = input.GetDirection();
|
||||
if (!inputDirection.Equals(Direction.Zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction
|
||||
&& (!IsHorizontal(inputDirection) || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border
|
||||
&& (!IsVertical(inputDirection) || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0)
|
||||
&& !pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection]))
|
||||
{ // Check if the requested direction does not have a wall
|
||||
if (inputDirection.x != 0)
|
||||
if (IsHorizontal(inputDirection))
|
||||
{ // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
|
||||
SetDirection(inputDirection + new Vector2(0, PositionToGrid(nextPosition).y - nextPosition.y).normalized);
|
||||
var directionToCenter = VerticalToDirection(PositionToGrid(nextPosition).y - nextPosition.y);
|
||||
SetDirection((Direction)((int)inputDirection | (int)directionToCenter));
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDirection(inputDirection + new Vector2(PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized);
|
||||
var directionToCenter = HorizontalToDirection(PositionToGrid(nextPosition).x - nextPosition.x);
|
||||
SetDirection((Direction)((int)inputDirection | (int)directionToCenter));
|
||||
}
|
||||
SetTargetDirection(VectorToDirection(inputDirection)); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
|
||||
SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
|
||||
|
||||
if (!followingPredefinedPath)
|
||||
{
|
||||
@@ -218,7 +220,7 @@ namespace Marro.PacManUdon
|
||||
return;
|
||||
}
|
||||
|
||||
if (frozen || direction.Equals(Vector2.zero))
|
||||
if (frozen || direction.Equals(Direction.Zero))
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionNone);
|
||||
animator.speed = 0;
|
||||
|
||||
Reference in New Issue
Block a user