/// <summary>
    /// Tries to move - handles different cases when the player can and cannot move
    /// </summary>
    private void AttemptMove(Vector2Int dir)
    {
        if (hitDirection == dir)
        {
            return;
        }

        // Hit to see if something is in the way
        RaycastHit2D hit;

        if (!CanMove(dir, out hit))
        {
            Stats       destructible = hit.transform.GetComponent <Stats>();
            Chest       chest        = hit.transform.GetComponent <Chest>();
            NPC         npc          = hit.transform.GetComponent <NPC>();
            DungeonDoor door         = hit.transform.GetComponent <DungeonDoor>();

            if (destructible && hitDirection == Vector2Int.zero)
            {
                hitDirection = dir;
                Invoke("ResetHitDirection", PlayerStats.instance.hitDelay.GetValue());
                Attack(destructible);
            }
            else if (chest)
            {
                ChestInventory.instance.OpenChest(chest);
            }
            else if (npc)
            {
                npc.OnNPCClicked();
            }
            else if (door)
            {
                door.Open();
            }
            else
            {
                animatorHandler.SetIdle(dir);
            }

            lighting.GenerateLight();

            return;
        }

        SetMoveSpeed(PlayerStats.instance.movementDelay.GetValue());

        // Initiate the movement
        Vector2 start = transform.position;
        Vector2 end   = start + dir;

        MovementTracker.instance.ClaimSpot(this, Vector2Int.FloorToInt(end));
        StartCoroutine(SmoothMovement(end));

        // Update certain other events
        DialoguePanel.instance.EndDialogue();
        ShopManager.instance.CloseShop();
        ChestInventory.instance.CloseChest();
        animatorHandler.AnimateMovement(dir);
    }
Example #2
0
    private void UpdatePosition()
    {
        float playerSpeed        = GetPlayerSpeed(_stats.Speed);
        float leftRightMove      = movementSpeed * moveLeftRightValue * Time.deltaTime;
        float forwardBackardMove = movementSpeed * moveForwardBackwardValue * Time.deltaTime;

        _playerAnimation.AnimateMovement(leftRightMove, forwardBackardMove);
        var vec = new Vector3(forwardBackardMove, 0, -leftRightMove);

        _characterController.SimpleMove(vec * playerSpeed);
    }
Example #3
0
    private void Update()
    {
        if (isLocalPlayer)
        {
            float x = Input.GetAxisRaw("Horizontal");
            float y = Input.GetAxisRaw("Vertical");

            if (x == 0 && y == 0)
            {
                if (playerAnim.x != 0 || playerAnim.y != 0)
                {
                    playerAnim.AnimateMovement(0, 0);
                }
            }
            else
            {
                playerAnim.AnimateMovement((int)x, (int)y);
            }

            movement.MovementPrediction(x, y);
            movement.Cmd_ServerMovePlayer(x, y);
        }
    }