Ejemplo n.º 1
0
    protected virtual void Update()
    {
        //Check if we're arrived to the target position
        if (transform.position == targetGridPosition.AsToIntVectr2())
        {
            progressToTarget = 0f;
            GridPosition     = targetGridPosition;
        }
        //If we update our grid position,and current input is valid

        if (GridPosition == targetGridPosition &&
            LevelGeneratorSystem.Grid[Mathf.Abs(targetGridPosition.y + currentInputDirection.y),
                                      Mathf.Abs(targetGridPosition.x + currentInputDirection.x)] != 1) //&& LevelGeneratorSystem.Grid[targetGridPosition.x, -targetGridPosition.y] != 1

        {
            targetGridPosition += currentInputDirection;
        }

        else if (GridPosition == targetGridPosition &&
                 LevelGeneratorSystem.Grid[Mathf.Abs(targetGridPosition.y + previousInputDirection.y),
                                           Mathf.Abs(targetGridPosition.x + previousInputDirection.x)] != 1
                 )
        {
            targetGridPosition += previousInputDirection;
        }

        if (GridPosition == targetGridPosition)
        {
            return;
        }

        progressToTarget  += movementSpeed * Time.deltaTime;
        transform.position = Vector3.Lerp(GridPosition.AsToIntVectr2(), targetGridPosition.AsToIntVectr2(), progressToTarget);
    }