void RefreshDirection(Touch touch) { currentPosition = GetTouchPosition(touch); Vector3 directionVector = GetDirectionVector(); bool hasMoved = directionVector.magnitude > sensivility; if (!hasMoved) { direction = j4dDirection.center; } else { float angle = Vector3.SignedAngle(startPointVector, directionVector, Vector3.back); j4dDirection newDirection = direction; if (angle >= 0 && angle < 90) { newDirection = j4dDirection.up; } else if (angle >= 90 && angle < 180) { newDirection = j4dDirection.right; } else if (angle >= -180 && angle < -90) { newDirection = j4dDirection.down; } else if (angle >= -90 && angle < 0) { newDirection = j4dDirection.left; } if (newDirection != direction) { direction = newDirection; onDirectionChanged.Invoke(); } } }
public void HandleJoystickAction(j4dDirection direction) { Debug.Log("Joystick moved: " + direction); if (direction == j4dDirection.up) { Vector3 nextPosition = new Vector3(0, 1, 0); boardManager.AttemptToMove(nextPosition); } if (direction == j4dDirection.right) { Vector3 nextPosition = new Vector3(1, 0, 0); boardManager.AttemptToMove(nextPosition); } if (direction == j4dDirection.down) { Vector3 nextPosition = new Vector3(0, -1, 0); boardManager.AttemptToMove(nextPosition); } if (direction == j4dDirection.left) { Vector3 nextPosition = new Vector3(-1, 0, 0); boardManager.AttemptToMove(nextPosition); } }
public void OnEnd() { j4dDirection direction = controller.direction; HandleJoystickAction(direction); }
void CleanState() { pivotPoint = null; currentPosition = null; direction = j4dDirection.center; }