More Direction
This commit is contained in:
@@ -452,7 +452,7 @@ namespace Marro.PacManUdon
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -175,13 +175,19 @@ MonoBehaviour:
|
||||
Data: 10|System.RuntimeType, mscorlib
|
||||
- Name:
|
||||
Entry: 1
|
||||
Data: UnityEngine.Vector2, UnityEngine.CoreModule
|
||||
Data: Marro.PacManUdon.Direction, Assembly-CSharp
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 10
|
||||
Entry: 7
|
||||
Data: 11|System.RuntimeType, mscorlib
|
||||
- Name:
|
||||
Entry: 1
|
||||
Data: System.Int32, mscorlib
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
@@ -196,7 +202,7 @@ MonoBehaviour:
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
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:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
@@ -220,7 +226,7 @@ MonoBehaviour:
|
||||
Data: inputVertical
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 12|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
Data: 13|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: inputVertical
|
||||
@@ -229,7 +235,7 @@ MonoBehaviour:
|
||||
Data: 10
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 10
|
||||
Data: 11
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
@@ -244,7 +250,7 @@ MonoBehaviour:
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
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:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
@@ -268,13 +274,13 @@ MonoBehaviour:
|
||||
Data: horizontalValue
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 14|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
Data: 15|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: horizontalValue
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 7
|
||||
Data: 15|System.RuntimeType, mscorlib
|
||||
Data: 16|System.RuntimeType, mscorlib
|
||||
- Name:
|
||||
Entry: 1
|
||||
Data: System.Single, mscorlib
|
||||
@@ -283,7 +289,7 @@ MonoBehaviour:
|
||||
Data:
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 15
|
||||
Data: 16
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
@@ -298,7 +304,7 @@ MonoBehaviour:
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
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:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
@@ -322,16 +328,16 @@ MonoBehaviour:
|
||||
Data: verticalValue
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 17|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
Data: 18|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: verticalValue
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 15
|
||||
Data: 16
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 15
|
||||
Data: 16
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
@@ -346,7 +352,7 @@ MonoBehaviour:
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
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:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
@@ -370,7 +376,7 @@ MonoBehaviour:
|
||||
Data: horizontalPriority
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
Data: 20|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: horizontalPriority
|
||||
@@ -394,7 +400,7 @@ MonoBehaviour:
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
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:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
@@ -418,13 +424,13 @@ MonoBehaviour:
|
||||
Data: player
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 21|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: player
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 7
|
||||
Data: 22|System.RuntimeType, mscorlib
|
||||
Data: 23|System.RuntimeType, mscorlib
|
||||
- Name:
|
||||
Entry: 1
|
||||
Data: VRC.SDKBase.VRCPlayerApi, VRCSDKBase
|
||||
@@ -433,7 +439,7 @@ MonoBehaviour:
|
||||
Data:
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 22
|
||||
Data: 23
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
@@ -448,7 +454,7 @@ MonoBehaviour:
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
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:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
|
||||
@@ -4,15 +4,14 @@
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using VRC.SDKBase;
|
||||
using VRC.Udon;
|
||||
using VRC.Udon.Common;
|
||||
|
||||
public class PlayerInput : UdonSharpBehaviour
|
||||
{
|
||||
public bool active;
|
||||
private GameManager gameManager;
|
||||
Vector2 inputHorizontal;
|
||||
Vector2 inputVertical;
|
||||
Direction inputHorizontal;
|
||||
Direction inputVertical;
|
||||
float horizontalValue;
|
||||
float verticalValue;
|
||||
bool horizontalPriority;
|
||||
@@ -21,8 +20,8 @@
|
||||
public void Initialize(GameManager gameManager)
|
||||
{
|
||||
this.gameManager = gameManager;
|
||||
inputHorizontal = Vector2.zero;
|
||||
inputVertical = Vector2.zero;
|
||||
inputHorizontal = Direction.Zero;
|
||||
inputVertical = Direction.Zero;
|
||||
horizontalPriority = false;
|
||||
player = Networking.LocalPlayer;
|
||||
}
|
||||
@@ -71,26 +70,23 @@
|
||||
horizontalValue = Math.Abs(value);
|
||||
if (value < -0.5)
|
||||
{
|
||||
inputHorizontal = Vector2.left;
|
||||
inputHorizontal = Direction.Left;
|
||||
if (horizontalValue >= verticalValue)
|
||||
{
|
||||
// horizontalPriority = true;
|
||||
SetPriority(true);
|
||||
}
|
||||
}
|
||||
else if (value > 0.5)
|
||||
{
|
||||
inputHorizontal = Vector2.right;
|
||||
inputHorizontal = Direction.Right;
|
||||
if (horizontalValue >= verticalValue)
|
||||
{
|
||||
// horizontalPriority = true;
|
||||
SetPriority(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
inputHorizontal = Vector2.zero;
|
||||
// horizontalPriority = false;
|
||||
inputHorizontal = Direction.Zero;
|
||||
SetPriority(false);
|
||||
}
|
||||
|
||||
@@ -106,26 +102,23 @@
|
||||
verticalValue = Math.Abs(value);
|
||||
if (value < -0.5)
|
||||
{
|
||||
inputVertical = Vector2.down;
|
||||
inputVertical = Direction.Up;
|
||||
if (verticalValue >= horizontalValue)
|
||||
{
|
||||
// horizontalPriority = false;
|
||||
SetPriority(false);
|
||||
}
|
||||
}
|
||||
else if (value > 0.5)
|
||||
{
|
||||
inputVertical = Vector2.up;
|
||||
inputVertical = Direction.Down;
|
||||
if (verticalValue >= horizontalValue)
|
||||
{
|
||||
// horizontalPriority = false;
|
||||
SetPriority(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
inputVertical = Vector2.zero;
|
||||
// horizontalPriority = true;
|
||||
inputVertical = Direction.Zero;
|
||||
SetPriority(true);
|
||||
}
|
||||
|
||||
@@ -141,11 +134,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// public Vector2[] GetDirections() {
|
||||
// return new Vector2[]{inputHorizontal, inputVertical};
|
||||
// }
|
||||
|
||||
public Vector2 GetDirection()
|
||||
public Direction GetDirection()
|
||||
{
|
||||
if (horizontalPriority)
|
||||
{
|
||||
@@ -156,48 +145,5 @@
|
||||
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;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user