More Direction

This commit is contained in:
2026-06-15 11:20:17 +02:00
parent f1281280fa
commit 77681fe0ca
4 changed files with 51 additions and 97 deletions

View File

@@ -452,7 +452,7 @@ namespace Marro.PacManUdon
bestDirection = direction; bestDirection = direction;
} }
} }
Debug.Log($"{gameObject.name} Closest next tile is in direction {bestDirection}"); //Debug.Log($"{gameObject.name} Closest next tile is in direction {bestDirection}");
return bestDirection; return bestDirection;
} }

View File

@@ -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}"); 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(); var inputDirection = input.GetDirection();
if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction if (!inputDirection.Equals(Direction.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 && (!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
&& (inputDirection.y == 0 || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0) && (!IsVertical(inputDirection) || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0)
&& !CheckCollisionInDirection(transform, nextPosition, inputDirection)) && !pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection]))
{ // Check if the requested direction does not have a wall { // 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 { // 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 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) if (!followingPredefinedPath)
{ {
@@ -218,7 +220,7 @@ namespace Marro.PacManUdon
return; return;
} }
if (frozen || direction.Equals(Vector2.zero)) if (frozen || direction.Equals(Direction.Zero))
{ {
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionNone); animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionNone);
animator.speed = 0; animator.speed = 0;

View File

@@ -175,13 +175,19 @@ MonoBehaviour:
Data: 10|System.RuntimeType, mscorlib Data: 10|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: UnityEngine.Vector2, UnityEngine.CoreModule Data: Marro.PacManUdon.Direction, Assembly-CSharp
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 7
Data: 10 Data: 11|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -196,7 +202,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 11|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 12|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -220,7 +226,7 @@ MonoBehaviour:
Data: inputVertical Data: inputVertical
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 12|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 13|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: inputVertical Data: inputVertical
@@ -229,7 +235,7 @@ MonoBehaviour:
Data: 10 Data: 10
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 10 Data: 11
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -244,7 +250,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 13|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 14|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -268,13 +274,13 @@ MonoBehaviour:
Data: horizontalValue Data: horizontalValue
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 14|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 15|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: horizontalValue Data: horizontalValue
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 15|System.RuntimeType, mscorlib Data: 16|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Single, mscorlib Data: System.Single, mscorlib
@@ -283,7 +289,7 @@ MonoBehaviour:
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 16
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -298,7 +304,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 16|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 17|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -322,16 +328,16 @@ MonoBehaviour:
Data: verticalValue Data: verticalValue
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 17|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 18|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: verticalValue Data: verticalValue
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 16
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 16
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -346,7 +352,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 18|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 19|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -370,7 +376,7 @@ MonoBehaviour:
Data: horizontalPriority Data: horizontalPriority
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 20|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: horizontalPriority Data: horizontalPriority
@@ -394,7 +400,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 20|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 21|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -418,13 +424,13 @@ MonoBehaviour:
Data: player Data: player
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 21|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: player Data: player
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 22|System.RuntimeType, mscorlib Data: 23|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: VRC.SDKBase.VRCPlayerApi, VRCSDKBase Data: VRC.SDKBase.VRCPlayerApi, VRCSDKBase
@@ -433,7 +439,7 @@ MonoBehaviour:
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 22 Data: 23
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -448,7 +454,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 23|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 24|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0

View File

@@ -4,15 +4,14 @@
using UdonSharp; using UdonSharp;
using UnityEngine; using UnityEngine;
using VRC.SDKBase; using VRC.SDKBase;
using VRC.Udon;
using VRC.Udon.Common; using VRC.Udon.Common;
public class PlayerInput : UdonSharpBehaviour public class PlayerInput : UdonSharpBehaviour
{ {
public bool active; public bool active;
private GameManager gameManager; private GameManager gameManager;
Vector2 inputHorizontal; Direction inputHorizontal;
Vector2 inputVertical; Direction inputVertical;
float horizontalValue; float horizontalValue;
float verticalValue; float verticalValue;
bool horizontalPriority; bool horizontalPriority;
@@ -21,8 +20,8 @@
public void Initialize(GameManager gameManager) public void Initialize(GameManager gameManager)
{ {
this.gameManager = gameManager; this.gameManager = gameManager;
inputHorizontal = Vector2.zero; inputHorizontal = Direction.Zero;
inputVertical = Vector2.zero; inputVertical = Direction.Zero;
horizontalPriority = false; horizontalPriority = false;
player = Networking.LocalPlayer; player = Networking.LocalPlayer;
} }
@@ -71,26 +70,23 @@
horizontalValue = Math.Abs(value); horizontalValue = Math.Abs(value);
if (value < -0.5) if (value < -0.5)
{ {
inputHorizontal = Vector2.left; inputHorizontal = Direction.Left;
if (horizontalValue >= verticalValue) if (horizontalValue >= verticalValue)
{ {
// horizontalPriority = true;
SetPriority(true); SetPriority(true);
} }
} }
else if (value > 0.5) else if (value > 0.5)
{ {
inputHorizontal = Vector2.right; inputHorizontal = Direction.Right;
if (horizontalValue >= verticalValue) if (horizontalValue >= verticalValue)
{ {
// horizontalPriority = true;
SetPriority(true); SetPriority(true);
} }
} }
else else
{ {
inputHorizontal = Vector2.zero; inputHorizontal = Direction.Zero;
// horizontalPriority = false;
SetPriority(false); SetPriority(false);
} }
@@ -106,26 +102,23 @@
verticalValue = Math.Abs(value); verticalValue = Math.Abs(value);
if (value < -0.5) if (value < -0.5)
{ {
inputVertical = Vector2.down; inputVertical = Direction.Up;
if (verticalValue >= horizontalValue) if (verticalValue >= horizontalValue)
{ {
// horizontalPriority = false;
SetPriority(false); SetPriority(false);
} }
} }
else if (value > 0.5) else if (value > 0.5)
{ {
inputVertical = Vector2.up; inputVertical = Direction.Down;
if (verticalValue >= horizontalValue) if (verticalValue >= horizontalValue)
{ {
// horizontalPriority = false;
SetPriority(false); SetPriority(false);
} }
} }
else else
{ {
inputVertical = Vector2.zero; inputVertical = Direction.Zero;
// horizontalPriority = true;
SetPriority(true); SetPriority(true);
} }
@@ -141,11 +134,7 @@
} }
} }
// public Vector2[] GetDirections() { public Direction GetDirection()
// return new Vector2[]{inputHorizontal, inputVertical};
// }
public Vector2 GetDirection()
{ {
if (horizontalPriority) if (horizontalPriority)
{ {
@@ -156,48 +145,5 @@
return inputVertical; return inputVertical;
} }
} }
public void OverrideDirection(Vector2 direction) // For recording the demo only, should not be used when shipped as it is very much a hack
{
inputHorizontal = new Vector2(direction.x, direction.y);
horizontalPriority = true;
}
// public Vector2 GetRotatedDirection() {
// return RotateDirection(GetDirection(), rotation);
// }
// public Vector2 RotateDirection(Vector2 direction, int rotation) {
// rotation = rotation%4;
// // Debug.Log(direction + " " + rotation);
// switch(rotation) {
// default:
// return direction;
// case 1:
// return new Vector2(direction.y, -direction.x);
// case 2:
// return new Vector2(-direction.x, -direction.y);
// case 3:
// return new Vector2(-direction.y, direction.x);
// }
// }
// public override void InputLookHorizontal(float value, UdonInputEventArgs args)
// {
// float rotation = player.GetRotation().eulerAngles.y;
// if(rotation > 45 && rotation <= 135) {
// // Debug.Log("Right");
// this.rotation = 1;
// } else if(rotation > 135 && rotation <= 225) {
// // Debug.Log("Backward");
// this.rotation = 2;
// } else if(rotation > 225 && rotation <= 315) {
// // Debug.Log("Left");
// this.rotation = 3;
// } else if(rotation > 315 || rotation <= 45) {
// // Debug.Log("Forward");
// this.rotation = 0;
// }
// }
} }
} }