public void Catch(bool buttonDown)
 {
     if (buttonDown == true)
     {
         catchScript.AttemptCatch();
     }
 }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (activeAI == true)
        {
            if (missCount > missThreshold)
            {
                missCount      = 0;
                anticipateMode = !anticipateMode;
                //Debug.Log("Switch: " + anticipateMode);
            }
            if (player2CatchScript.holdingDisc == true)
            {
                //If in possession of two discs, in the lead, and at least one disc has points, let that one go until it has 4, mark it as target until it is caught or intercepted

                if (Mathf.Abs(Mathf.Abs(player1Reference.position.x) - Mathf.Abs(GoalLine.position.x)) < Mathf.Abs(Mathf.Abs(player1Reference.position.x) - Mathf.Abs(Teleporter1.position.x)) && throwTargetConfirmed == false)
                {
                    //Player is closer to goal, throw toward goal but away from player
                    //throwTargetVector = GoalLine.position - player2CatchBox.position;
                    if (Mathf.Abs(player1Reference.position.z - 6) < Mathf.Abs(player1Reference.position.z + 6))
                    {
                        throwTargetVector = new Vector3(player1Reference.position.x - transform.position.x, 0, -6 - transform.position.z);
                    }
                    else
                    {
                        throwTargetVector = new Vector3(player1Reference.position.x - transform.position.x, 0, 6 - transform.position.z);
                    }
                    throwTimer  = 0;
                    timeToThrow = Mathf.Abs(Mathf.Atan2(throwTargetVector.normalized.x, throwTargetVector.normalized.z) - Mathf.Atan2(player2CatchBox.forward.x, player2CatchBox.forward.z));

                    throwTargetConfirmed = true;
                }
                else if (Mathf.Abs(Mathf.Abs(player1Reference.position.x) - Mathf.Abs(GoalLine.position.x)) >= Mathf.Abs(Mathf.Abs(player1Reference.position.x) - Mathf.Abs(Teleporter1.position.x)) && throwTargetConfirmed == false)
                {
                    //Player is closer to teleporter, throw toward teleporter but away from player
                    //throwTargetVector = Teleporter2.position - transform.GetChild(0).position;
                    if (Mathf.Abs(player1Reference.position.z - 6) < Mathf.Abs(player1Reference.position.z + 6))
                    {
                        throwTargetVector = new Vector3(2 * Teleporter2.position.x + (player1Reference.position.x - transform.position.x), 0, -6 - transform.position.z);
                    }
                    else
                    {
                        throwTargetVector = new Vector3(2 * Teleporter2.position.x + (player1Reference.position.x - transform.position.x), 0, 6 - transform.position.z);
                    }
                    throwTimer  = 0;
                    timeToThrow = Mathf.Abs(Mathf.Atan2(throwTargetVector.normalized.x, throwTargetVector.normalized.z) - Mathf.Atan2(player2CatchBox.forward.x, player2CatchBox.forward.z));

                    throwTargetConfirmed = true;
                }
                throwTimer += Time.deltaTime;
                //timer based on distance from target vector
                if (throwTimer < timeToThrow / 8)
                {
                    rotationInterface.Rotate(throwTargetVector.normalized.x, throwTargetVector.normalized.z);
                }
                else
                {
                    throwTargetConfirmed = false;
                    player2CatchScript.AttemptThrow();
                    if (discThrown == false)
                    {
                        discThrown = true;
                        if (missCount > 0)
                        {
                            missCount -= 1;
                        }
                    }
                }
                targetDisc = null;
            }
            else
            {
                if (discThrown == false && catchAttempted == true)
                {
                    missCount     += 4;
                    catchAttempted = false;
                }
                else if (discThrown == true && catchAttempted == true)
                {
                    discThrown     = false;
                    catchAttempted = false;
                }

                timer += Time.deltaTime;
                if (timer > thinkTime)
                {
                    timer = 0;
                    TargetADisc();
                }

                originRelativePosition = new Vector3(GoalLine.position.x + 10, GoalLine.position.y, GoalLine.position.z) - transform.GetChild(0).position;
                if (targetDisc != null)
                {
                    targetDiscRelativePosition   = targetDisc.position - transform.GetChild(0).position;
                    targetDiscAnticipatePosition = targetDiscRelativePosition + (targetDisc.forward * targetDisc.GetComponent <DiscScript>().GetSpeed());

                    //transform.GetChild(0).LookAt(targetDisc);

                    rotationInterface.Rotate(targetDiscRelativePosition.normalized.x, targetDiscRelativePosition.normalized.z);
                    //transform.GetChild(0).rotation = new Quaternion(0, transform.GetChild(0).rotation.y, 0, transform.GetChild(0).rotation.w);
                    if (targetDisc.position.x > GoalLine.position.x && targetDisc.position.x < Teleporter2.position.x)
                    {
                        if (targetDisc.GetComponent <DiscScript>().GetSpeed() >= moveSpeed)
                        {
                            if (anticipateMode == true)
                            {
                                movementVector = new Vector3(targetDiscAnticipatePosition.x, 0, targetDiscAnticipatePosition.z);
                            }
                            else
                            {
                                movementVector = new Vector3(targetDiscRelativePosition.x, 0, targetDiscRelativePosition.z);
                            }
                        }
                        else if (targetDisc.GetComponent <DiscScript>().GetSpeed() < moveSpeed || Mathf.Abs((targetDiscAnticipatePosition - transform.GetChild(0).position).magnitude) <= 24)
                        {
                            movementVector = new Vector3(targetDiscRelativePosition.x, 0, targetDiscRelativePosition.z);
                        }
                    }
                    else
                    {
                        movementVector = new Vector3(originRelativePosition.x, 0, targetDiscRelativePosition.z);
                    }


                    player2Controller.Move(movementVector.normalized * moveSpeed * Time.deltaTime);


                    if (player2CatchScript.GetAbleToCatch() == true && Mathf.Abs(targetDiscRelativePosition.magnitude) < 5)
                    {
                        player2CatchScript.AttemptCatch();
                        if (catchAttempted == false)
                        {
                            catchAttempted = true;
                        }
                    }
                }
                else if (targetDisc == null && targetDiscLowPriority != null)
                {
                    timer += Time.deltaTime;
                    if (timer > thinkTime)
                    {
                        timer                 = 0;
                        targetDisc            = targetDiscLowPriority;
                        targetDiscLowPriority = null;
                    }
                }
                else if (targetDisc == null && targetDiscLowPriority == null)
                {
                    movementVector = new Vector3(originRelativePosition.x, 0, originRelativePosition.z);
                    player2Controller.Move(movementVector.normalized * moveSpeed * Time.deltaTime);
                }
            }
        }
    }