public void monsterLampLit(GameObject litLamp) { Debug.Log("MonsterLampLit"); GameObject lamp; if (targetLamp == null) { lamp = currentLamp; } else { lamp = targetLamp; } lightSourceController lController = lamp.GetComponentInParent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lightsourcontroller"); } else { GameObject[] adjacentLamps = lController.getAdjacentSources(); foreach (GameObject adjacentlamp in adjacentLamps) { if (litLamp == adjacentlamp) { targetLamp = litLamp; currentTarget = litLamp.transform.position; nav.SetDestination(currentTarget); movingToLamp = true; } } } }
void controlLureImage() { //check if light is in traveller radius GameObject trav = GameObject.FindGameObjectWithTag("Traveller"); if (trav == null) { Debug.Log("Could not find the traveller"); } travellerScript tScript = trav.GetComponent <travellerScript>(); if (tScript == null) { Debug.Log("could not find tScript"); } //get the current lamp that the traveller is at // get its adjacent lamps from light controller // check against our current target //if it is //lureImage.sprite = travellerLureIcon; //go through all monster tagged objects //for each grab script and get the current lamp foreach (GameObject g in GameObject.FindGameObjectsWithTag("Monster")) { EnemyMovement eMovement = g.GetComponent <EnemyMovement>(); if (eMovement == null) { Debug.Log("Could not find monster movement script"); } GameObject lamp = eMovement.findCurrentLamp(); if (lamp != null) { lightSourceController lController = lamp.GetComponent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find light source controller"); } //if (lController.getAdjacentSources().) if (checkAdjacent(lController.getAdjacentSources())) { //check if monster is in monster radius //lureImage.enabled = true; //lureImage.sprite = monsterLureIcon; } } } }
public void moveToLamp() { //Debug.Log("in the move to lamp"); if (currentLamp == null) // initial gamestate when monster is first placed { float distance = Mathf.Infinity; foreach (GameObject lamp in lamps) //this part is also not quite working { if (Vector3.Distance(transform.position, lamp.transform.position) < distance) // edge case, does not take into account lit lamp { distance = Vector3.Distance(transform.position, lamp.transform.position); currentLamp = lamp; } } } else //general case of finding lamps { lightSourceController lController = currentLamp.GetComponentInParent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lightsourcontroller"); } GameObject[] adjacentLamps = lController.getAdjacentSources(); List <GameObject> possibleTargets = new List <GameObject>(); foreach (GameObject adjacentlamp in adjacentLamps) { lightSourceController adjLController = adjacentlamp.GetComponentInParent <lightSourceController>(); int lightType = adjLController.getCurrentLightType(); if (lightType == 1 || lightType == 3) { possibleTargets.Add(adjacentlamp); } } if (lController.getCurrentLightType() == 1 || lController.getCurrentLightType() == 3) //possible bug need to fix when lamps are implemented { currentTarget = transform.position; nav.SetDestination(currentTarget); targetLamp = null; movingToLamp = false; return; } GameObject[] targetLamps = possibleTargets.ToArray(); if (targetLamps.Length == 0) { targetLamps = adjacentLamps; //WILL NEED TO DEBUGGGGGGG //Debug.Log("PLEASE PLACE BREAKPOINT HERE unsure if this will behave correctly"); } int ran = Random.Range(0, targetLamps.Length); //unsure doesnt work with length - 1, tried the remove 1 now it works???!!! targetLamp = targetLamps[ran]; currentTarget = targetLamp.transform.position; nav.SetDestination(currentTarget); movingToLamp = true; } }
public void monsterLampLit(GameObject litLamp) { float distance = Mathf.Infinity; GameObject newCurrentLamp = null; foreach (GameObject newlamp in lamps) //this part is also not quite working { if (Vector3.Distance(transform.position, newlamp.transform.position) < distance) // edge case, does not take into account lit lamp { distance = Vector3.Distance(transform.position, newlamp.transform.position); newCurrentLamp = newlamp; } } Debug.Log("MonsterLampLit"); if (newCurrentLamp == litLamp) { monsterAnim.SetTrigger("nearbyLitLamp"); Debug.Log("inhere1"); targetLamp = litLamp; currentTarget = litLamp.transform.position; nav.SetDestination(currentTarget); movingToLamp = true; if (!isBaby) { isDistracted = true; } } lightSourceController lController = newCurrentLamp.GetComponentInParent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lightsourcontroller"); } else { GameObject[] adjacentLamps = lController.getAdjacentSources(); foreach (GameObject adjacentlamp in adjacentLamps) { if (litLamp == adjacentlamp) { monsterAnim.SetTrigger("nearbyLitLamp"); Debug.Log("inhere2"); targetLamp = litLamp; currentTarget = litLamp.transform.position; nav.SetDestination(currentTarget); movingToLamp = true; if (!isBaby) { isDistracted = true; } } } } }
public void monsterLampLit(GameObject litLamp) { if (isStunned) { return; } if (monsterAnim.GetCurrentAnimatorStateInfo(0).IsName("Chase") && !((getLampPriority(litLamp) == 3))) { currentTarget = traveller.position; nav.SetDestination(currentTarget); nav.isStopped = false; isChaseTrav = true; return; } float distance = Mathf.Infinity; GameObject newCurrentLamp = null; foreach (GameObject newlamp in lamps) //this part is also not quite working { if (Vector3.Distance(transform.position, newlamp.transform.position) < distance) // edge case, does not take into account lit lamp { distance = Vector3.Distance(transform.position, newlamp.transform.position); newCurrentLamp = newlamp; } } // Debug.Log("MonsterLampLit"); if ((newCurrentLamp == litLamp) && (getLampPriority(targetLamp) <= getLampPriority(litLamp))) { monsterAnim.SetTrigger("nearbyLitLamp"); //Debug.Log("inhere1"); targetLamp = litLamp; currentTarget = litLamp.transform.position; nav.SetDestination(currentTarget); nav.isStopped = false; movingToLamp = true; bodyAnim.SetBool("isMoving", true); if (!isBaby) { isDistracted = true; } } lightSourceController lController = newCurrentLamp.GetComponentInParent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lightsourcontroller"); } else { GameObject[] adjacentLamps = lController.getAdjacentSources(); foreach (GameObject adjacentlamp in adjacentLamps) { if ((litLamp == adjacentlamp) && (getLampPriority(targetLamp) <= getLampPriority(litLamp))) { Debug.Log("target:" + getLampPriority(targetLamp) + " litlamp:" + getLampPriority(litLamp)); monsterAnim.SetTrigger("nearbyLitLamp"); // Debug.Log("inhere2"); targetLamp = litLamp; currentTarget = litLamp.transform.position; nav.SetDestination(currentTarget); nav.isStopped = false; movingToLamp = true; bodyAnim.SetBool("isMoving", true); if (!isBaby) { isDistracted = true; } } } } }
void Update() { if (bodyAnim.GetCurrentAnimatorStateInfo(0).IsName("Attacking")) { //for now do nothing while animation completes //channge nothing, it can go back to doing what it does after // var rotation = Quaternion.LookRotation(traveller.position); var rotation = Quaternion.LookRotation(traveller.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 10f); nav.SetDestination(transform.position); return; } /* * else { //once animation is done make sure we can move again * if (nav.isStopped) * nav.isStopped = false; * } */ //for testing purposes //if (Input.GetKeyDown(KeyCode.M)) //{ // startAttack(); // } if (currentAttackCooldown != 0) { currentAttackCooldown = Mathf.Clamp(currentAttackCooldown -= Time.deltaTime, 0f, attackCooldownValue); } //monster sounds; possibly temporary, depending if we use 3D audio controller //The attackSound is almost definitely temporary, assuming we will someday have //and attack state soundTimer += Time.deltaTime; float distanceFromTraveler = Vector3.Distance(transform.position, traveller.transform.position); if (distanceFromTraveler < 1 && !isDistracted) { if (startAttack()) { attackSound.enabled = true; attackSound.volume = 0.5f; if (!attackSound.isPlaying) { if (roamingSound.isPlaying) { roamingSound.Pause(); } attackSound.Play(); } } } if (distanceFromTraveler < 3 && !tHealth.isDead && !tMovement.closeToExit)// && distanceFromTraveler > 1) { if (soundTimer < 2) { roamingSound.enabled = true; roamingSound.volume = (1 / distanceFromTraveler) / 2; if (!roamingSound.isPlaying && !attackSound.isPlaying) { roamingSound.Play(); } } else { roamingSound.Stop(); roamingSound.enabled = false; } } else { if (!roamingSound.isPlaying && roamingSound.enabled) { roamingSound.Play(); } roamingSound.volume = 0; } if (soundTimer > 4) { roamingSound.volume = 0; soundTimer = 0f; } //end of monster sound control if (monsterAnim.GetCurrentAnimatorStateInfo(0).IsName("Stunned")) { if (isChaseTrav) { isChaseTrav = false; } nav.SetDestination(transform.position); nav.velocity = Vector3.zero; nav.isStopped = true; //Monster sounds roamingSound.enabled = false; attackSound.enabled = false; timer += Time.deltaTime; int countDown = 9 - (int)timer; popUp2.GetComponent <WorldSpaceObjectController>().setPopUpText(countDown.ToString()); if (timer > 9) { popUp2.SetActive(false); monsterAnim.SetTrigger("recovered"); //Monster sounds roamingSound.enabled = true; timer = 0f; movingToLamp = false; isStunned = false; } return; } else if (monsterAnim.GetCurrentAnimatorStateInfo(0).IsName("Chase")) { currentTarget = traveller.position; nav.SetDestination(currentTarget); nav.isStopped = false; isChaseTrav = true; if (Vector3.Distance(roamCenterPoint, traveller.position) >= maxRoamDistance) { monsterAnim.SetTrigger("travellerLost"); //monster sounds roamingSound.enabled = true; attackSound.enabled = false; movingToLamp = false; isChaseTrav = false; } if (distanceFromTraveler < 1) { isChaseTrav = false; nav.isStopped = true; } } else if (monsterAnim.GetCurrentAnimatorStateInfo(0).IsName("Alerted")) { //Debug.Log("Alerted"); isChaseTrav = false; isDistracted = false; RaycastHit hit; if (Physics.Raycast(transform.position + upward, direction.normalized, out hit, Mathf.Infinity)) { if (hit.collider.gameObject.transform == traveller) { monsterAnim.SetTrigger("travellerSpotted"); } else { monsterAnim.SetTrigger("isLooking"); } } } else { isChaseTrav = false; if (!movingToLamp) { // not currently moving, find new place to move to nextLamp(lampQueue); } else if (Vector3.Distance(transform.position, currentTarget) < lampDistance) { movingToLamp = false; isDistracted = false; nav.SetDestination(transform.position); nav.velocity = Vector3.zero; nav.isStopped = true; currentLamp = findCurrentLamp(); } else { if (!isLit(targetLamp)) { float timeRemaining = 0f; int lampPriority = 0; lightSourceController lScript = targetLamp.GetComponentInParent <lightSourceController>(); if (lScript != null) { GameObject[] adjLamps = lScript.getAdjacentSources(); foreach (GameObject lamp in adjLamps) { if (isLit(lamp)) { if ((timeRemaining < getTimeRemaining(lamp)) && (lampPriority <= getLampPriority(lamp))) { targetLamp = lamp; timeRemaining = getTimeRemaining(lamp); movingToLamp = true; bodyAnim.SetBool("isMoving", true); } } } } } currentTarget = targetLamp.transform.position; nav.SetDestination(currentTarget); nav.isStopped = false; } } //Debug.Log(isChaseTrav); if (((Vector3.Distance(transform.position, currentTarget) < lampDistance) && !isChaseTrav) || isStunned) { bodyAnim.SetBool("isMoving", false); } else { bodyAnim.SetBool("isMoving", true); } /* * if (!isStunned) * { * if (movingToLamp != bodyAnim.GetBool("isMoving")) * { * //Debug.Log("called switch"); * bodyAnim.SetBool("isMoving", movingToLamp); * } * } */ }