Fixes
This commit is contained in:
@@ -130,30 +130,29 @@ namespace Marro.PacManUdon
|
||||
|
||||
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
|
||||
{
|
||||
if (CrossesTileCenter(position, nextPosition, Direction.Left) // If pacman is moving horizontally, check if he may cross the center of a tile in that axis
|
||||
if (CrossesTileCenter(position, nextPosition, Direction.Left) // If pacman is moving horizontally, check if he may cross the center of a tile in that axis
|
||||
&& (!IsHorizontal(targetDirection) || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)HorizontalComponent(direction)])))
|
||||
{ // If the target direction is in the other axis or if we're about to run into a wall
|
||||
nextPosition.x = PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis
|
||||
nextPosition.x = PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis
|
||||
SetDirection(VerticalComponent(direction));
|
||||
Debug.Log($"{gameObject} crossed X tile center from {position}, nextPosition is now {nextPosition} and direction is now {direction}");
|
||||
//Debug.Log($"{gameObject} crossed X tile center from {position}, nextPosition is now {nextPosition} and direction is now {direction}");
|
||||
}
|
||||
|
||||
if (CrossesTileCenter(position, nextPosition, Direction.Down) // See comments above but now vertical
|
||||
if (CrossesTileCenter(position, nextPosition, Direction.Down) // See comments above but now vertical
|
||||
&& (!IsVertical(targetDirection) || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)])))
|
||||
{
|
||||
nextPosition.y = PositionToGrid(nextPosition).y;
|
||||
SetDirection(HorizontalComponent(direction));
|
||||
Debug.Log($"{gameObject} crossed Y tile center from {position} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
|
||||
//Debug.Log($"{gameObject} crossed Y tile center from {position} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
|
||||
}
|
||||
|
||||
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.x, 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.y, 5) - 0.5) % 1 != 0)
|
||||
&& !pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection]))
|
||||
{ // Check if the requested direction does not have a wall
|
||||
&& !pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection])) // Check if the requested direction does not have a wall
|
||||
{
|
||||
// Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
|
||||
if (IsHorizontal(inputDirection))
|
||||
{ // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
|
||||
{
|
||||
var directionToCenter = VerticalToDirection(PositionToGrid(nextPosition).y - nextPosition.y);
|
||||
SetDirection((Direction)((int)inputDirection | (int)directionToCenter));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user