Exemplo n.º 1
0
 public void FillPathVolume(MoveDirection dir, int step)
 {
     int index = 0;
     while (index <= step) {
         pathFillers.Add((GameObject)Instantiate(invisibleObstacle, transform.position + dir.AsVector() * index, transform.rotation));
         ++index;
     }
 }
Exemplo n.º 2
0
 public float GetObstacleOffsetStep(MoveDirection dir, int step)
 {
     int toObstacleStep = step;
     float checkDistance = step + 0.5f;
     RaycastHit hit;
     if (Physics.Raycast(transform.position, dir.AsVector(), out hit, checkDistance, obstacleLayerMask)) {
         toObstacleStep = Mathf.RoundToInt(Vector3.Distance(transform.parent.position, hit.transform.position + getObstacleCompensationVector(dir)));
     }
     return toObstacleStep;
 }
Exemplo n.º 3
0
    private void updateNextPoint()
    {
        currentStep = moveUtils.GetCurrentStep();

        Vector3 nextPointOffsetVector = direction.AsVector() * currentStep;

        nextPoint = agent.transform.position + nextPointOffsetVector;

        if (willCollideWithObstacleOnMove())
        {
            currentStep = (int)getStepCorrectedByObstacle();
            nextPoint   = agent.transform.position + currentStep * direction.AsVector();
            direction   = moveUtils.HandleObstacle(currentStep);
            fillPathVolume();
            return;
        }
        fillPathVolume();

        direction = moveUtils.GetNextDirection();
    }
Exemplo n.º 4
0
    public bool WillCollide(MoveDirection dir, int step)
    {
        foreach (GameObject pathFiller in pathFillers) {
            Destroy(pathFiller);
        }

        if (Physics.Raycast(transform.position, dir.AsVector(), step, obstacleLayerMask)) {
            return true;
        }
        return false;
    }
Exemplo n.º 5
0
    public float GetObstacleOffsetStep(MoveDirection dir, int step)
    {
        int        toObstacleStep = step;
        float      checkDistance  = step + 0.5f;
        RaycastHit hit;

        if (Physics.Raycast(transform.position, dir.AsVector(), out hit, checkDistance, obstacleLayerMask))
        {
            toObstacleStep = Mathf.RoundToInt(Vector3.Distance(transform.parent.position, hit.transform.position + getObstacleCompensationVector(dir)));
        }
        return(toObstacleStep);
    }
Exemplo n.º 6
0
    private void FixedUpdate()
    {
        if (InvertPacman.gameState != GameState.Play)
        {
            return;
        }

        currentDirection = GetNextDirection();

        var totalMovement = currentDirection.AsVector() * moveSpeed * Time.fixedDeltaTime;

        transform.position += totalMovement;
    }
Exemplo n.º 7
0
    public bool WillCollide(MoveDirection dir, int step)
    {
        foreach (GameObject pathFiller in pathFillers)
        {
            Destroy(pathFiller);
        }

        if (Physics.Raycast(transform.position, dir.AsVector(), step, obstacleLayerMask))
        {
            return(true);
        }
        return(false);
    }
Exemplo n.º 8
0
    // Update is called once per frame
    private void FixedUpdate()
    {
        if (InvertPacman.gameState != GameState.Play)
        {
            return;
        }

        var pressedDirection = MoveDirection.Idle;

        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W) || Input.GetAxis("Vertical") > DEADZONE)
        {
            pressedDirection = MoveDirection.Up;
        }
        else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S) || Input.GetAxis("Vertical") < -DEADZONE)
        {
            pressedDirection = MoveDirection.Down;
        }

        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A) || Input.GetAxis("Horizontal") < -DEADZONE)
        {
            pressedDirection = MoveDirection.Left;
        }
        else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D) || Input.GetAxis("Horizontal") > DEADZONE)
        {
            pressedDirection = MoveDirection.Right;
        }

        if (pressedDirection != MoveDirection.Idle)
        {
            currentDirection = pressedDirection;
        }

        var totalMovement = currentDirection.AsVector() * moveSpeed * Time.fixedDeltaTime;

        player.transform.position += totalMovement;
    }
Exemplo n.º 9
0
    public void FillPathVolume(MoveDirection dir, int step)
    {
        int index = 0;

        while (index <= step)
        {
            pathFillers.Add((GameObject)Instantiate(invisibleObstacle, transform.position + dir.AsVector() * index, transform.rotation));
            ++index;
        }
    }