More Direction
This commit is contained in:
@@ -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