// Update is called once per frame
    void Update()
    {
        //get the camera center screen 2d point converted to a 3d location
        Vector3 screenPoint = cam.WorldToViewportPoint(target.transform.position);

        Debug.Log("player is seen" + playerSeen());
        //check if the player is within the convertedbounding view of the camera and invoke the player seen function
        onScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1 && playerSeen();

        Debug.Log("player is screen" + onScreen);
        if (onScreen)
        {
            //only update the player's status once on the first time the mirror sees the player
            if (onScreen != oldOnScreen)
            {
                targetScript.numReflection++;
                oldOnScreen = onScreen;
            }
        }
        else
        {
            //only update the status of the player to have one less mirror see the player on the first time that the player is out of view
            if (oldOnScreen != onScreen)
            {
                targetScript.numReflection -= 1;
                oldOnScreen = onScreen;
                //reset the monster's position on exiting the mirrors view
                targetScript.ResetThismonster();
            }
        }
    }
Esempio n. 2
0
    //when player enters
    void OnTriggerEnter(Collider col)
    {
        Debug.Log(this.name);

        layerThemeForMirror.PlayOneShot(warp);
        if (col.gameObject == player)
        {
            Debug.Log(col.name + "trigger enter");
            //Debug.Log(col.gameObject.transform.position);
            //Debug.Log(next.position + Vector3.Scale(next.forward, offsetSpawn));
            // Instantiate(player, next.position, player.transform.rotation);

            charController.enabled    = false;                                     //**************************************IMPORTANT****************
            player.transform.position = next.transform.position + offsetSpawnNext; //the charachor controller script MUST BE DISABLED!!!!!!
            player.transform.rotation = transform.rotation;                        //**************************************IMPORTANT****************
            charController.enabled    = true;

            //reset player's understranding of its location....can be revised into the future for the player to figure out itspotention teleport on capture postion based on this last mirror
            playerScript.lastMirror = playerScript.thisMirror;
            playerScript.thisMirror = next;
            playerScript.ResetThismonster();


            //@BJ this changes music to the next one
            StartCoroutine(transition(playerScript.layerTheme, 1, 0));



            //Destroy(col.gameObject);
            //player.transform.Translate(0, 1000, 0);
            //Destroy(player);
            //}
        }
        else
        {
            //teleport any object
            col.gameObject.transform.position = next.transform.position + offsetSpawnNext;
        }
    }
    // Update is called once per frame
    void Update()
    {
        //create directional vector, need to find direction that monster must traverse to move reach player
        dirUnitVector = Vector3.Normalize(player.transform.position - transform.position);

        //rotate this quaternion(monster's) to the coressponding angle facing the player/target
        transform.LookAt(player.transform);

        //check four orthognal locations of solid surfaces(floor,ceiling,wall right, and wall left), get the position of the closest of the four
        Vector3 monstLoc = getNearestSurface();

        //get the differece in distance between
        float dist = Vector3.Magnitude(monstLoc - transform.GetChild(0).transform.position);

        //attach monstermesh(child of monster object) to the ground. unsuccessfuly lerped(linear interpalation/smoothed) position
        transform.GetChild(0).transform.position = Vector3.Lerp(monstLoc, transform.GetChild(0).transform.position, dist * .05f * Time.deltaTime);

        //if the player is within view AND not within a certin distance
        if ((playerScript.isSeen && (Mathf.Abs((player.transform.position - transform.position).magnitude) >= killDist)) || isDopple)
        {
            //move the player fowards(z axis) towards the player/target
            transform.Translate(0, 0, movingRate * Time.deltaTime);
        }
        else if ((Mathf.Abs((player.transform.position - transform.position).magnitude) < killDist))//&& !isDopple)
        {
            //code for monster capturing player
            // Debug.Log("captured " + masterPlayer.name + "teleport from"+ masterPlayerScript.thisMirror.name + "  to " + masterPlayerScript.lastMirror.name + "\n from "+ masterPlayerScript.thisMirror.transform.position + " to " + masterPlayerScript.lastMirror.transform.position + offsetSpawn +"\nat " + masterPlayer.transform.position);
            //Debug.Log("player1st@" + masterPlayer.transform.position);
            masterCharController.enabled    = false;
            masterPlayer.transform.position = masterPlayerScript.lastMirror.transform.position + offsetSpawn;
            masterCharController.enabled    = true;

            //reset the position of this monster(doppleganger or player's) and the makes sure the player will reset theirs
            masterPlayerScript.ResetThismonster();
            reset();

            //update spawn position with respect to the new teleport destination from being captured
            offsetSpawn = masterPlayerScript.lastMirror.GetComponent <teleport>().offsetSpawn;


            //update player's known position within the node list to figure out position
            masterPlayerScript.thisMirror = masterPlayerScript.thisMirror.GetComponent <teleport>().prev;
            masterPlayerScript.lastMirror = masterPlayerScript.thisMirror.GetComponent <teleport>().prev;

            //capture animation
            monsterAnim.Play("notice");

            //MUSIC TRANSITION!!!! @BJ over here!!!! this changes the music that the player is listening to the new teleporter's song ( parallel proccess)
            StartCoroutine(transition(masterPlayerScript.layerTheme, 1, 0));
        }

        if ((Mathf.Abs((player.transform.position - transform.position).magnitude) < killDist + .5f))
        {
            //execute scream on delay
            monsterVoice.Play();

            // monsterVoice.clip = voices[Random.Range(0, voices.Length - 1)];
        }
        if (masterPlayerScript.move.x != 0 && masterPlayerScript.move.z != 0)
        {
            //make the monster animate walk if the player is walking (this condition ^^ may not work)
            anim.Play("walk");
        }
        else
        {
            anim.Play("idle");
        }
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        Vector3 screenPoint = cam.WorldToViewportPoint(target.transform.position);

        //overideCheck = (transform.position - target.transform.position).magnitude < distCheck;

        onScreen = (screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1 && playerSeen());// || ( overideCheck)

        //Debug.Log(playerSeen() +"overall" + onScreen);
        if (onScreen)
        {
            Debug.Log(playerSeen() + "overall" + onScreen);
            Vector3 distFromCamera = transform.position - target.transform.position;
            Debug.Log(this.transform.parent.name);
            if (onScreen != oldOnScreen)
            {
                // a ton of stuff to set up the dopple ganger ask Jordan for clarification.... watch for hierachy incase this gets an error
                targetScript.numReflection++;

                doppleganger = Instantiate(target, mirror2.localPosition + distFromCamera, transform.rotation);
                Destroy(doppleganger.GetComponent <CharMove>());
                Destroy(doppleganger.GetComponent <CharacterController>());
                doppleganger.transform.GetChild(1).GetComponent <Camera>().enabled       = false;
                doppleganger.transform.GetChild(1).GetComponent <CameraHandle>().enabled = false;
                oldOnScreen = onScreen;
                doppleganger.transform.GetChild(1).GetComponent <AudioListener>().enabled = false;
                doppleganger.name = "doppleGanger";
                doppleganger.transform.GetChild(2).GetComponent <MonsterTrickle>().player   = doppleganger;
                doppleganger.transform.GetChild(2).GetComponent <MonsterTrickle>().isDopple = true;
            }
            //Debug.Log(mirror2.rotation.eulerAngles);
            Quaternion yzSwitch = Quaternion.Euler(0, mirror2.rotation.eulerAngles.y - transform.rotation.eulerAngles.y, 0);
            //.Debug.Log(yzSwitch.eulerAngles);
            if (!switchStartingDirection)
            {
                distFromCamera.z = -distFromCamera.z;
            }
            else
            {
                distFromCamera.x = -distFromCamera.x;
            }
            distFromCamera.y = distFromCamera.y - Mathf.Abs(mirror2.transform.position.y - transform.position.y);

            doppleganger.transform.position = Vector3.Scale(mirror2.transform.position + transformRotation(yzSwitch, distFromCamera), new Vector3(1, 1, 1));  // + new Vector3(1, target.transform.position.y, 1);
            doppleganger.transform.LookAt(mirror2);
            // doppleganger.transform.position = new Vector3(1, Mathf.Abs(target.transform.position.y - mirror2.transform.position.y), 1);//mirror2.transform.lossyScale.y / 2
            // Debug.Log("traget" + target.transform.GetChild(1).transform.childCount);
            //Debug.Log("Player" + doppleganger.transform.GetChild(1).transform.childCount);

            //if target camera does not have item AND  doppleganger camera  has item
            if (target.transform.GetChild(1).transform.childCount <= 0 && doppleganger.transform.GetChild(1).transform.childCount > 0)// && target.transform.GetChild(1).transform.childCount <= 0 )
            {
                Debug.Log("remove item");
                Destroy(doppleganger.transform.GetChild(1).transform.GetChild(0).gameObject);
            }
            //else if target's camera has item AND doppleganger camera does not
            else if (target.transform.GetChild(1).transform.childCount > 0 && doppleganger.transform.GetChild(1).transform.childCount <= 0)
            {
                Debug.Log("add item");
                Transform tempCam      = target.transform.GetChild(1);
                Transform tempItem     = target.transform.GetChild(1).transform.GetChild(0);
                Vector3   itemDistHold = tempCam.position - tempItem.position;
                Transform child        = Instantiate(tempItem, doppleganger.transform.position + (doppleganger.transform.forward * itemDistHold.magnitude), doppleganger.transform.rotation);
                child.parent = doppleganger.transform.GetChild(1);
            }
            //distFromCamera.x = -distFromCamera.x;
            //doppleganger.transform.position = mirror2.transform.localPosition + (distFromCamera);// + mirror2.transform.TransformDirection(Vector3.up) ;
        }
        else
        {
            //only update the status of the player to have one less mirror see the player on the first time that the player is out of view
            if (oldOnScreen != onScreen)
            {
                targetScript.numReflection -= 1;
                oldOnScreen = onScreen;
                //clears doppleganger
                Destroy(doppleganger);
                //reset the monster's position on exiting the mirrors view
                targetScript.ResetThismonster();
            }
        }
    }