Example #1
0
    /**
     *  @brief   Handles the given command
     *  @param   command, the command to handle
     *  @return  returns true when the command is done, and return false when the command is still not done
     */
    bool HandleCommand(HumanCommand command)
    {
        CurrentState = command.state;

        switch (command.state)
        {
        case CharacterStates.WALK:
        case CharacterStates.RUN:
            Vector3 dir  = command.target - transform.position;
            float   dist = dir.sqrMagnitude;

            if (CurrentState == CharacterStates.WALK)
            {
                rigid.MovePosition(transform.position + dir.normalized * walkSpeed * Time.deltaTime);
            }
            else
            {
                rigid.MovePosition(transform.position + dir.normalized * runSpeed * Time.deltaTime);
            }

            if (dist <= 0.001f)
            {
                return(true);
            }
            break;

        default:
            return(true);
        }
        return(false);
    }
Example #2
0
    /**
     *  @brief   Change the state of the AI to the desired state
     *  @param   state, the state to change into
     */
    public void ChangeState(CharacterStates state)
    {
        HumanCommand command = new HumanCommand();

        command.state = state;
        commandQueue.Enqueue(command);
    }
Example #3
0
    /**
     *  @brief   Run to the designated position stated, will also change the state of the AI to Run
     *  @param   position, the designated position for the AI to run to
     */
    public void RunTo(Vector3 position)
    {
        HumanCommand command = new HumanCommand();

        transform.LookAt(position);

        // Forced fixed due to models not facing the right direction, due to time constraint.
        transform.Rotate(new Vector3(0.0f, 180.0f, 0.0f));

        command.state  = CharacterStates.RUN;
        command.target = position;
        commandQueue.Enqueue(command);
    }