override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        waitScript = animator.GetComponent <CaptureWait>();
        witchLogic = animator.GetComponent <WitchLogic>();

        targetPlayer = witchLogic.getTargetPlayer();
        targetPlayer.GetComponent <PlayerLogic>().gotCaught(); // make player disabled


        originalFruitDropTime = fruitDropTime;
        originalFruitLossRate = fruitLossRate;

        //goal = targetPlayer.GetComponent<PlayerLogic>().getFruitCounter() * 5;

        goal = getGoal(targetPlayer.GetComponent <PlayerLogic>().getFruitCounter());

        dropTimer = fruitDropTime;

        gameManager = witchLogic.getGameManager();

        Debug.Log("Witch Capture behaviour");
    }
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     witchLogic   = animator.GetComponent <WitchLogic>();
     targetPlayer = witchLogic.getTargetPlayer();
 }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        origin    = transform.position;
        direction = Vector3.down; //* transform.rotation.x;
        angle     = lightComponent.spotAngle;
        RaycastHit hit1;          // only used for sphere radius calculation
        RaycastHit hit2;
        Ray        landingRay = new Ray(transform.position, Vector3.down);

        /*
         * if (Physics.Raycast(from, dirToTarget, out hit, (1 << LayerMask.NameToLayer("Sight") | (1 << LayerMask.NameToLayer("OtherLayerMaskName"))))
         */

        if (Physics.Raycast(landingRay, out hit1))
        {
            Debug.DrawRay(transform.position, Vector3.down * hit1.distance);
            // calculate the spehre radius
            // opposite = adjacent * tan(angle)
            // radius = distance to collider * tan(spotlight angle / 2) --> using half the angle to obtain a right angle
            sphereRadius = hit1.distance * Mathf.Tan(Mathf.Deg2Rad * (this.lightComponent.spotAngle / 2));
            distance1    = hit1.distance;


            /*
             *
             * // detect player with xz position + radius of light, when colliders are above it
             *
             * if (Math.Abs(transform.position.x - GameObject.FindWithTag("Player1").transform.position.x) <= Mathf.Epsilon && Mathf.Abs(transform.position.z - GameObject.FindWithTag("Player1").transform.position.z)<= Mathf.Epsilon)
             * {
             *  Debug.LogWarning("Got Player");
             * }
             *
             */


            if (Physics.SphereCast(origin, sphereRadius, direction, out hit2, hit1.distance, layerMask, QueryTriggerInteraction.UseGlobal))
            {
                currentHitObject   = hit2.transform.gameObject;
                currentHitDistance = hit2.distance + sphereRadius; //to use sphere as a semisphere

                if (hit2.collider.tag == "Player1" || hit2.collider.tag == "Player2")
                {
                    Debug.Log("Spherecast Got Player");

                    player = hit2.collider.transform;


                    if (canCapture(player) && !FindObjectOfType <GameManager>().isGameOver())
                    {
                        if (witchLogic.getTargetPlayer() != null && witchLogic.getTargetPlayer().gameObject != player.gameObject)
                        {
                            // caught a player while chasing another player

                            PlayerLogic otherPlayer = witchLogic.getTargetPlayer().GetComponent <PlayerLogic>();
                            otherPlayer.stopChasingMe();
                        }

                        player.GetComponent <PlayerLogic>().setCanBeChased(false);
                        witchLogic.setTargetPlayer(player);


                        //animator.SetTrigger("capture");
                        animator.SetBool("isIdle", false);
                        animator.SetBool("isChasing", false);
                        animator.SetBool("isPatrolling", false);
                        animator.SetBool("isCapturing", true);
                    }
                }
            }
        }
    }