// Update is called once per frame void Update() { if (Time.time - lastTime > 8f) { lastTime = Time.time; // do a new (or the same) action every 8 sec float randomNum = Random.Range(-10, 10); if (currState == AnimalBehavior.Idle && randomNum < 6) { // switch to eating anim.SetBool("isIdle", false); anim.SetBool("isEating", true); currState = AnimalBehavior.Eating; } else if (currState == AnimalBehavior.Eating && randomNum > 8) { // switch to idle anim.SetBool("isEating", false); anim.SetBool("isIdle", true); currState = AnimalBehavior.Idle; } } }
public ActionResult DeleteConfirmed(int id) { AnimalInfo animalInfo = db.AnimalInfo.Find(id); AnimalBehavior animalBehavior = db.AnimalBehavior.Find(id); AnimalHistory animalHistory = db.AnimalHistory.Find(id); ChipIdentification chipIdentification = db.ChipIdentification.Find(id); AdditionalContact additionalContact = db.AdditionalContact.Find(id); AdditionalPetInfo additionalPetInfo = db.AdditonalPetInfo.Find(id); Insurance insurance = db.Insurance.Find(id); MedicalHistory medicalHistory = db.MedicalHistory.Find(id); SecondaryContact secondaryContact = db.SecondaryContact.Find(id); TrackingOperations trackingOperations = db.TrackingOperations.Find(id); db.AnimalInfo.Remove(animalInfo); db.AnimalBehavior.Remove(animalBehavior); db.AnimalHistory.Remove(animalHistory); db.ChipIdentification.Remove(chipIdentification); db.AdditionalContact.Remove(additionalContact); db.AdditonalPetInfo.Remove(additionalPetInfo); db.Insurance.Remove(insurance); db.MedicalHistory.Remove(medicalHistory); db.SecondaryContact.Remove(secondaryContact); db.TrackingOperations.Remove(trackingOperations); db.SaveChanges(); return(RedirectToAction("Index")); }
private float lastTime; // store last seen time to get elapsed time // Use this for initialization void Start() { anim = GetComponent <Animator>(); anim.SetBool("isIdle", true); currState = AnimalBehavior.Idle; lastTime = Time.time; }
public ActionResult DeleteConfirmed(int id) { AnimalBehavior animalBehavior = db.AnimalBehavior.Find(id); db.AnimalBehavior.Remove(animalBehavior); db.SaveChanges(); return(RedirectToAction("Index")); }
Vector3 scaledHerdForce() { // if (group) { // return group.groupVel / 10f; // } Vector3 herdForce = AnimalBehavior.superiorNeighborForce(this, neighborDistance); return(AnimalBehavior.scaleByDistance(herdForce, herdForce.magnitude, neighborDistance, neighborDistance)); }
public Snapshot(string name, float dist, Vector3 screenPlace, Vector3 cameraForward, Vector3 targetForward, Texture2D screenshot, AnimalBehavior state) { targetName = name; distanceAway = dist; screenPlacement = determineScreenPlace(screenPlace); orientation = determineOrientation(cameraForward, targetForward); theScreenshot = screenshot; animalState = state; }
public ActionResult Edit([Bind(Include = "Id,AnimalId,AggressionComments")] AnimalBehavior animalBehavior) { if (ModelState.IsValid) { db.Entry(animalBehavior).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(animalBehavior)); }
public ActionResult Create([Bind(Include = "Id,AnimalId,AggressionComments")] AnimalBehavior animalBehavior) { if (ModelState.IsValid) { db.AnimalBehavior.Add(animalBehavior); db.SaveChanges(); return(RedirectToAction("Create", "AnimalHistories")); } return(View(animalBehavior)); }
void faceForward() { if (_vel.magnitude < 1 || isPlayer) { return; } float diff = AnimalBehavior.angleBetweenVector3s(transform.forward, _vel); float divisor = canSeeParent ? 15f : 10f; if (Mathf.Abs(diff) > 2) { transform.eulerAngles = new Vector3(0, (transform.eulerAngles.y + diff / divisor), 0); } }
// GET: AnimalBehaviors/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AnimalBehavior animalBehavior = db.AnimalBehavior.Find(id); if (animalBehavior == null) { return(HttpNotFound()); } return(View(animalBehavior)); }
// Update is called once per frame void Update() { //Debug.Log(anim.GetCurrentAnimatorStateInfo(0).IsName("Armature|Idle")); if (Time.time - lastTime > 7f) { lastTime = Time.time; // do a new (or the same) action every 7 sec float randomNum = Random.Range(-10, 10); if (currState == AnimalBehavior.Idle && randomNum > 2 && randomNum < 4) { // switch to eating anim.SetBool("isIdle", false); anim.SetBool("isEating", true); currState = AnimalBehavior.Eating; } else if (currState == AnimalBehavior.Eating && randomNum > 4) { // switch to idle anim.SetBool("isEating", false); anim.SetBool("isIdle", true); currState = AnimalBehavior.Idle; } else if (currState == AnimalBehavior.Idle && randomNum > 6) { // switch to sitting if idle anim.SetBool("isIdle", false); anim.SetBool("isSitting", true); currState = AnimalBehavior.Sitting; } else if (currState == AnimalBehavior.Sitting && randomNum < 2) { // switch to getting up anim.SetBool("isSitting", false); anim.SetBool("isGettingUp", true); currState = AnimalBehavior.GettingUp; } else if (currState == AnimalBehavior.GettingUp) { // go to idle from getting up anim.SetBool("isGettingUp", false); anim.SetBool("isIdle", true); currState = AnimalBehavior.Idle; } } }
// shoot a ray from the camera to hit a target object (namely the animals that will be photographed) void shootRay() { RaycastHit hit; Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(r, out hit)) { if (hit.collider != null) { //Debug.Log("ray hit: " + hit.transform); // capture animals if (hit.transform.gameObject.tag == "animal") { //Debug.Log(hit.transform); // get distance // make sure to take into account FOV! (i.e. if camera is zoomed in, take that perceived distance into account) // default FOV starts at 50, so take fraction of 50 Vector3 diff = hit.transform.position - player.transform.position; float distance = diff.magnitude; distance *= (Camera.main.fieldOfView / 50); //Debug.Log("distance to player: " + distance); // find out where object is located in viewport (2d) Vector3 viewportPos = cam.WorldToViewportPoint(hit.transform.position); //Debug.Log("position of object in viewport: " + viewportPos); // get the orientation of the animal relative to the camera // i.e., is it looking away, towards? use dot product for this Vector3 targetForward = hit.transform.forward; Vector3 cameraForward = cam.transform.forward; //Debug.Log(cameraForward); float product = Vector3.Dot(targetForward, cameraForward); //Debug.Log(product); // what is the animal doing? // call getState from its interface implementation AnimalBehavior animalState = hit.transform.gameObject.GetComponent <Animal>().getState(); //Debug.Log(animalState); IEnumerator coroutine = getSnapshot(hit.transform.name, distance, viewportPos, targetForward, cameraForward, animalState); StartCoroutine(coroutine); } } } }
// Update is called once per frame void Update() { if (Time.time - lastTime > 6f && isNotAngry) { lastTime = Time.time; // do a new (or the same) action every 6 sec float randomNum = Random.Range(-10, 10); if (currState == AnimalBehavior.Idle && randomNum > 2 && randomNum < 4) { // switch to eating anim.SetBool("isIdle", false); anim.SetBool("isEating", true); currState = AnimalBehavior.Eating; } else if (currState == AnimalBehavior.Eating && randomNum > 4) { // switch to idle anim.SetBool("isEating", false); anim.SetBool("isIdle", true); currState = AnimalBehavior.Idle; } else if (currState == AnimalBehavior.Idle && randomNum > 6) { // switch to sitting if idle anim.SetBool("isIdle", false); anim.SetBool("isSitting", true); currState = AnimalBehavior.Sitting; } else if (currState == AnimalBehavior.Sitting && randomNum < 2) { // switch to getting up anim.SetBool("isSitting", false); anim.SetBool("isGettingUp", true); currState = AnimalBehavior.GettingUp; } else if (currState == AnimalBehavior.GettingUp) { // go to idle from getting up anim.SetBool("isGettingUp", false); anim.SetBool("isIdle", true); currState = AnimalBehavior.Idle; } } }
// get the state as a string private string getStateString(AnimalBehavior a) { if (a == AnimalBehavior.Idle) { return("isIdle"); } else if (a == AnimalBehavior.Eating) { return("isEating"); } else if (a == AnimalBehavior.Sitting) { return("isSitting"); } else if (a == AnimalBehavior.GettingUp) { return("isGettingUp"); } else { return("isAngry"); } }
Vector3 scaledParentForce() { Vector3 parentForce = AnimalBehavior.parentForce(this); return(AnimalBehavior.scaleByDistance(parentForce, parentForce.magnitude, 100.0f, neighborDistance / 2.0f)); }
Vector3 scaledCrowdForce() { Vector3 crowdForce = AnimalBehavior.superiorNeighborForce(this, crowderDistance); return(AnimalBehavior.inverseScaleByDistance(crowdForce, crowdForce.magnitude, crowderDistance, 0f)); }
// taking a snapshot IEnumerator getSnapshot(string targetName, float distance, Vector3 viewportPos, Vector3 cameraForward, Vector3 targetForward, AnimalBehavior state) { // hide the canvas ui temporarily - this script is attached to the canvas ui.enabled = false; yield return(waitForEnd); Texture2D tex = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false); tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false); // capture screen tex.Apply(); // update texture // add snapshot Snapshot newPic = new Snapshot(targetName, distance, viewportPos, cameraForward, targetForward, tex, state); GameManager.GetComponent <GameManager>().updatePicturesTaken(newPic); //picturesTaken.Add(newPic); // save pic as test to disk newPic.saveScreenshot(); // restore ui ui.enabled = true; }
// Update is called once per frame void Update() { if (behaviors.Count > 0) { CurrentBehavior = behaviors.Peek(); var currentBehavior = behaviors.Peek(); //is the animal currently chasing or evading? if (currentBehavior == chase || currentBehavior == evade) { //fight or flight mode, animal wont add new behaviors until the current finishes } else { //is the animal looking for something to chase or run from? if (Agressive) { //CHECK IF HUNTER IS CLOSE ENOUGH TO CAUSE CHASE if (Vector3.Distance(hunter.transform.position, agent.gameObject.transform.position) <= SpookDistance && currentBehavior != chase) { chase.target = hunter; behaviors.Push(chase); } else { //CHECK IF THE ANIMAL CAN SEE THE HUNTER, DEAD ANIMAL OR ANIMAL AND CHASE IF ANIMAL SPOT SPOT THEM if (vision.visibleTargets.Count > 0) { if (vision.visibleTargets.Contains(hunter.transform)) { chase.target = hunter; behaviors.Push(chase); } else { //MAKE SURE WHAT I WAS LOOKING AT DIDN'T DISAPPEAR (stops null errors after an animal dies) Transform destroyedTest = vision.visibleTargets[0].transform; if (destroyedTest != null) { //look for dead things if none are avalible hunt the closest animal float smallestDistance = Vector3.Distance(gameObject.transform.position, vision.visibleTargets[0].position); bool foundDeadAnimal = false; GameObject agressiontarget = vision.visibleTargets[0].gameObject; foreach (Transform target in vision.visibleTargets) { if (target != null) { if (target.gameObject.tag == "DeadAnimal") { foundDeadAnimal = true; if (smallestDistance >= Mathf.Min(smallestDistance, Vector3.Distance(gameObject.transform.position, target.gameObject.transform.position))) { smallestDistance = Mathf.Min(smallestDistance, Vector3.Distance(gameObject.transform.position, target.gameObject.transform.position)); agressiontarget = target.gameObject; } } if (foundDeadAnimal == false && target.gameObject.tag == "Animal") { if (smallestDistance >= Mathf.Min(smallestDistance, Vector3.Distance(gameObject.transform.position, target.gameObject.transform.position))) { smallestDistance = Mathf.Min(smallestDistance, Vector3.Distance(gameObject.transform.position, target.gameObject.transform.position)); agressiontarget = target.gameObject; } } } } if (foundDeadAnimal) { //sets walkto target to the closest animal if no dead animals or hunters were found walkToTargets.Push(agressiontarget); //walkTo.target = agressiontarget; behaviors.Push(walkTo); } else { //sets chase target to the closest animal if no dead animals or hunters were found chase.target = agressiontarget; behaviors.Push(chase); } } } } } } else { //CHECK IF THE HUNTER IS CLOSE ENOUGH TO SPOOK THE ANIMAL if (Vector3.Distance(hunter.transform.position, agent.gameObject.transform.position) <= SpookDistance && currentBehavior != evade) { //Debug.Log("ANIMAL SPOOKED"); evade.target = hunter; behaviors.Push(evade); } else { //CHECK IF THE ANIMAL CAN SEE THE HUNTER OR AGRESSIVE ANIMAL AND RUN IF ANIMAL SPOT THEM //TO BE ADDED //IF THEY CANT SEE ANYONE DO WHATEVER THEY WERE DOING } } } } else { //Debug.Log("animal has no behaviors, returning to den"); walkTo.target = Den; behaviors.Push(walkTo); } //does the behavior //Debug.Log("HUNTER " + hunter.gameObject.transform.position); DoBehavior(); ////is the animal spooked, chasing, or should it continue what it was doing? //if (behaviors.Count > 0) //{ // currentBehavior = behaviors.Peek(); //} //else //{ // //currentbehavior is just used to see if the behavior is evade or not check below so no errors happen if the count is empty // currentBehavior = null; //} //if (currentBehavior != chase || currentBehavior != evade) //{ // if (Agressive) // { // //CHECK IF THE HUNTER IS CLOSE ENOUGH TO CHASE // if (Vector3.Distance(hunter.transform.position, agent.gameObject.transform.position) <= ChaseDistance) // { // //Debug.Log("ANIMAL NOW CHASEING HUNTER"); // chase.target = hunter; // behaviors.Push(chase); // } // } // else // { // //CHECK IF THE HUNTER IS CLOSE ENOUGH TO SPOOK THE ANIMAL // if (Vector3.Distance(hunter.transform.position, agent.gameObject.transform.position) <= SpookDistance && currentBehavior != evade) // { // //Debug.Log("ANIMAL SPOOKED"); // evade.target = hunter; // behaviors.Push(evade); // } // } //} //else //{ // if (behaviors.Count > 0) // { // behaviors.Peek().DoBehavior(this); // behaviors.Peek().UpdateBehavior(this); // } // else // { // Debug.Log("animal has no behaviors, returning to den"); // walkTo.target = Den; // behaviors.Push(walkTo); // } //} }