public void doneExploding() { currentJellyCatState = JellyCatState.GOAL_MOVE; }
void Update() { curTime += Time.deltaTime; Vector2 screenPointOfCat = ArCamera.WorldToScreenPoint(this.transform.position); switch (currentJellyCatState) { case JellyCatState.DYING: SetAnimationState("AvoidCondition"); if (curTime > DeathTimePeriod) { MoveCatToOrigin(); currentJellyCatState = JellyCatState.REBORN; curTime = 0f; } else { curTime += Time.deltaTime; curTimeOverPeriodRatio = curTime / DeathTimePeriod; this.transform.Rotate(0.0f, Time.deltaTime * 360f * RotationsOnDeath / DeathTimePeriod, 0f, Space.Self); // spin this.transform.localScale = new Vector3(1 - curTimeOverPeriodRatio, 1, 1 - curTimeOverPeriodRatio); // shrink } break; case JellyCatState.REBORN: SetAnimationState("AttractCondition"); if (curTime > DeathTimePeriod) { if (isGoalSeeking) { currentJellyCatState = JellyCatState.GOAL_MOVE; } else { currentJellyCatState = JellyCatState.IDLE_MOVE; } curTime = 0f; } else { curTime += Time.deltaTime; curTimeOverPeriodRatio = curTime / RespawnTimePeriod; this.transform.Rotate(0, -Time.deltaTime * 360f * RotationsOnDeath / DeathTimePeriod, 0, Space.Self); // opposite spin this.transform.localScale = new Vector3(curTimeOverPeriodRatio, 1, curTimeOverPeriodRatio); // grow } break; case JellyCatState.GOAL_MOVE: SetAnimationState("AttractCondition"); // get goal position if (currentGoal.activeSelf) { isGoalSeeking = true; Vector3 heading = currentGoalTransform.position - this.transform.position; leftOrRight = AngleDir(this.transform.forward, heading, this.transform.up); Vector2 screenPointOfGoal = ArCamera.WorldToScreenPoint(currentGoalTransform.position); // TURN ANGLE this.transform.Rotate(0.0f, leftOrRight * GoalRotationSpeed * Time.deltaTime, 0.0f, Space.Self); // FORWARD MOVE this.transform.position += this.transform.forward * StartSpeed * Time.deltaTime; if (Mathf.Abs(Vector2.Distance(screenPointOfCat, screenPointOfGoal)) < GoalClosenessThreshholdPixels) { currentJellyCatState = JellyCatState.GOAL_IDLE; } } goto case JellyCatState.COMMON_MOVE; case JellyCatState.GOAL_IDLE: SetAnimationState("SleepCondition"); goto default; case JellyCatState.IDLE_MOVE: SetAnimationState(""); isGoalSeeking = false; if (curTime > curDirectionChangePeriod) { leftOrRight *= -1; curTime = 0f; NewDirectionChangePeriod(); } // BACK AND FORTH TURN this.transform.Rotate(0.0f, leftOrRight * IdleRotationSpeed * Time.deltaTime, 0.0f, Space.Self); // FORWARD MOVE this.transform.position += this.transform.forward * StartSpeed * Time.deltaTime; goto case JellyCatState.COMMON_MOVE; case JellyCatState.AVOID: SetAnimationState("AvoidCondition"); if (curTime > AvoidDurationPeriod) { if (isGoalSeeking) { currentJellyCatState = JellyCatState.GOAL_MOVE; } else { currentJellyCatState = JellyCatState.IDLE_MOVE; } curTime = 0f; } else { curTime += Time.deltaTime; // FORWARD MOVE this.transform.position += this.transform.forward * StartSpeed * Time.deltaTime; } goto default; case JellyCatState.COMMON_MOVE: // JELLY WIGGLE Vector3 vec = new Vector3((Mathf.Sin(Time.time) / 2) + 1.5f, 1, (Mathf.Sin(12 * Time.time) / 2) + 1.5f); transform.localScale = vec; goto default; default: // default behavior rules below: // FALLOFF == DEATH // bottom left is 0,0, bottom right is 0,1, top left is 1,0, top right is 1,1 if (screenPointOfCat.x < PitDeathClosenessThreshholdPixels) { currentJellyCatState = JellyCatState.DYING; } else if (screenPointOfCat.x > ArCamera.pixelWidth - PitDeathClosenessThreshholdPixels) { currentJellyCatState = JellyCatState.DYING; } if (screenPointOfCat.y < PitDeathClosenessThreshholdPixels) { currentJellyCatState = JellyCatState.DYING; } else if (screenPointOfCat.y > ArCamera.pixelHeight - PitDeathClosenessThreshholdPixels) { currentJellyCatState = JellyCatState.DYING; } // AVOID CUCUMBER if (Cucumber.gameObject.activeSelf) { Vector2 screenPointOfCucumber = ArCamera.WorldToScreenPoint(Cucumber.transform.position); if (Mathf.Abs(Vector2.Distance(screenPointOfCat, screenPointOfCucumber)) < CucumberClosenessThreshholdPixels) { BackupAndFlip(); currentJellyCatState = JellyCatState.AVOID; curTime = 0f; } } // AVOID BROOM if (Broom.gameObject.activeSelf) { Vector2 screenPointOfCucumber = ArCamera.WorldToScreenPoint(Cucumber.transform.position); if (Mathf.Abs(Vector2.Distance(screenPointOfCat, screenPointOfCucumber)) < CucumberClosenessThreshholdPixels) { BackupAndFlip(); currentJellyCatState = JellyCatState.AVOID; curTime = 0f; } } // FISH TRIGGER if (Fish.gameObject.activeSelf) { setGoal(Fish.gameObject, Fish.transform); Vector2 screenPointOfFish = ArCamera.WorldToScreenPoint(Fish.transform.position); if (Mathf.Abs(Vector2.Distance(screenPointOfCat, screenPointOfFish)) < GoalClosenessThreshholdPixels) { currentJellyCatState = JellyCatState.GOAL_IDLE; isGoalSeeking = false; } else { currentJellyCatState = JellyCatState.GOAL_MOVE; isGoalSeeking = true; } } else { setGoal(Launchpad.gameObject, Launchpad.transform); } break; } }