Exemplo n.º 1
0
    void SetState(AgentState state)
    {
        if (currentState == state)
        {
            return;
        }

        currentState = state;

        switch (currentState)
        {
        case AgentState.Idle:
            //Do nothing
            thirdPersonCharacter.Move(Vector3.zero, false, false);

            break;

        case AgentState.Moving:
            navAgent.SetDestination(target.gameObject.transform.position);
            thirdPersonCharacter.Move(navAgent.desiredVelocity, false, false);
            break;

        case AgentState.Attacking:
            thirdPersonCharacter.Move(Vector3.zero, false, false);
            thirdPersonCharacter.Attack();
            break;

        default:
            Debug.LogError("Unexpected state: " + state.ToString());
            break;
        }
    }
Exemplo n.º 2
0
    //runs when game is in combat mode
    public bool DoTurn()
    {
        line.gameObject.SetActive(true);//open line that shows movement target
        if (AP > 0)
        {
            Vector3 movementPoint = transform.position;
            movementPoint = movementRange(APRange);

            float distance = Vector3.Distance(transform.position, target.transform.position);

            Debug.Log("doing action!");//attack or move wrt to distance
            AP--;
            if (distance < attackRange)
            {
                character.Attack();
            }
            else
            {
                agent.SetDestination(movementPoint);
            }

            if (agent.remainingDistance > agent.stoppingDistance)//stop when close to target
            {
                character.Move(agent.desiredVelocity, false, false);
            }
            else
            {
                character.Move(Vector3.zero, false, false);
            }
            return(false);
        }
        return(true);
    }
Exemplo n.º 3
0
    public bool DoTurn()//when in combat
    {
        line.gameObject.SetActive(true);
        if (AP > 0)//only able to act while having action points
        {
            Vector3 movementPoint = transform.position;
            movementPoint = movementRange(APRange);//retract clicked point to movement range
            //works good because it is also visualized
            //Debug.Log(movementPoint);

            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Input.GetMouseButtonDown(0))//click
            {
                Debug.Log("clicked!");
                AP--;
                if (Physics.Raycast(ray, out hit))//if on enemy and in distance, hit, otherwise run there
                {
                    if (hit.collider.tag == "Enemy" && Vector3.Distance(character.transform.position, hit.collider.transform.position) < attackRange)
                    {
                        character.Attack();
                    }
                    else
                    {
                        agent.SetDestination(movementPoint);
                    }
                }
            }
            //adjust movement animation according to stopping distance
            if (agent.remainingDistance > agent.stoppingDistance)
            {
                character.Move(agent.desiredVelocity, false, false);
            }
            else
            {
                character.Move(Vector3.zero, false, false);
            }
            return(false);
        }
        return(true);
    }