private void MoveTo(Vector3 dest) { Vector3 maxMovement = dest - gameObject.transform.position; Vector3 partialMovement = maxMovement.normalized * movementSpeed * Time.deltaTime; if (partialMovement.sqrMagnitude >= maxMovement.sqrMagnitude) //if we reached the destination { //position on the destination gameObject.transform.Translate(maxMovement, Space.World); movingToDestination = false; if (leftHome.position == dest) { status = AnturaContollerState.LEFTHOME; } else { status = AnturaContollerState.RIGHTHOME; } StartCoroutine(co_AnturaNextDesicion()); } else //make the progress for this frame { gameObject.transform.Translate(partialMovement, Space.World); } }
private void MoveToNewDestination(Transform dest) { destination = dest.position; gameObject.transform.rotation = dest.rotation; movingToDestination = true; status = AnturaContollerState.WALKING; }
void Update() { if (movingToDestination) { MoveTo(destination); } else if (status == AnturaContollerState.DANCING) { danceDuration -= Time.deltaTime; if (danceDuration < 0) { status = AnturaContollerState.FINISHINGDANICING; antura.State = AnturaAnimationStates.walking; finishDance = 1f; } } else if (status == AnturaContollerState.FINISHINGDANICING) { finishDance -= Time.deltaTime; if (finishDance < 0) { status = AnturaContollerState.WALKING; movingToDestination = true; } } }
IEnumerator co_AnturaNextDesicion() { switch (status) { case AnturaContollerState.LEFTHOME: yield return(new WaitForSeconds(UnityEngine.Random.Range(1, 5))); MoveToNewDestination(rightHome); antura.State = AnturaAnimationStates.walking; status = AnturaContollerState.WALKING; break; case AnturaContollerState.RIGHTHOME: yield return(new WaitForSeconds(UnityEngine.Random.Range(1, 5))); MoveToNewDestination(leftHome); antura.State = AnturaAnimationStates.walking; status = AnturaContollerState.WALKING; break; default: break; } }
void Awake() { antura = gameObject.GetComponent <AnturaAnimationController>(); antura.State = AnturaAnimationStates.sitting; antura.WalkingSpeed = 0; //walk-0, run-1 status = AnturaContollerState.LEFTHOME; StartCoroutine(co_AnturaNextDesicion()); }
private void AnturaInteractions(AnturaContollerState eState) { if (eState == AnturaContollerState.BARKING) //Antura scared the LL { AnturaReachedLetter(); } else if (eState == AnturaContollerState.COMINGBACK) //Antura is returning to his place { AnturaGoingAway(); } }
void OnTriggerEnter(Collider other) { //Debug.Log("DD Antura ontrigger"); if (other.tag == "Marker") { danceDuration = 3.5f * UnityEngine.Random.Range(1, 3); status = AnturaContollerState.DANCING; antura.State = AnturaAnimationStates.dancing; movingToDestination = false; } }
/// <summary> /// Force Antura to interrupt current action and go back. /// </summary> public void ForceAnturaToGoBack() { //We do not care about states of Sleeping, RotatingOnStart and ComingBack if (m_eAnturaState == AnturaContollerState.SLEEPING || m_eAnturaState == AnturaContollerState.ROTATION || m_eAnturaState == AnturaContollerState.COMINGBACK) { return; } // handled cases else if (m_eAnturaState == AnturaContollerState.REACHINGLETTER) { //swap dest and start Vector3 _v3Temp = m_v3StartPosition; m_v3StartPosition = m_v3Destination; m_v3Destination = _v3Temp; m_bMovingToDestination = true; //set new state m_eAnturaState = AnturaContollerState.COMINGBACK; } else if (m_eAnturaState == AnturaContollerState.TURN_TO_BARK) { m_bMovingToDestination = true; //m_oAntura.SetAnimation(m_eAnimationOnMoving); m_oAntura.State = m_eAnimationOnMoving; //set new state m_eAnturaState = AnturaContollerState.COMINGBACK; } else if (m_eAnturaState == AnturaContollerState.BARKING) { //m_oAntura.IsBarking = false; //m_oAntura.SetAnimation(m_eAnimationOnMoving); m_oAntura.State = m_eAnimationOnMoving; m_bMovingToDestination = true; //set new state m_eAnturaState = AnturaContollerState.COMINGBACK; } //launch event if (OnStateChanged != null) { OnStateChanged(m_eAnturaState); } }
/// <summary> /// This is called by Antura controller with the change state event to apply any /// needed interactions. /// </summary> /// <param name="eState">Current state for Antura</param> private void AnturaInteractions(AnturaContollerState eState) { if (eState == AnturaContollerState.BARKING) //Antura scared the LL { AnturaReachedLetter(); } else if (eState == AnturaContollerState.COMINGBACK) //Antura is returning to his place { if (m_LetterObjectView.GetState() != LLAnimationStates.LL_tickling) //if the LL is tickling antura didn't reach it (fix) { AnturaGoingAway(); } } }
void Awake() { /*m_Antura = gameObject.GetComponent<Antura>(); * m_StartPosition = gameObject.transform.position; * m_Antura.SetAnimation(AnturaAnim.SitBreath);*/ m_oAntura = gameObject.GetComponent <AnturaAnimationController>(); m_v3StartPosition = m_oAntura.gameObject.transform.position; m_eAnturaState = AnturaContollerState.SLEEPING; m_fBarkTimeProgress = 0; m_v3Destination = m_oDestination.position; m_oAntura.State = AnturaAnimationStates.sitting; m_oAntura.WalkingSpeed = 0; //walk-0, run-1 m_eAnturaState = AnturaContollerState.ROTATION; m_bRotatingToTarget = true; }
/// <summary> /// Progress through the states for Antura: standby->movetoletter->rotationback->bark->movetostandby->rotation->... /// </summary> private void AnturaNextTransition() { if (m_eAnturaState == AnturaContollerState.SLEEPING) //go to the letter { m_bMovingToDestination = true; //m_oAntura.SetAnimation(m_eAnimationOnMoving); m_oAntura.State = m_eAnimationOnMoving; m_eAnturaState = AnturaContollerState.REACHINGLETTER; } else if (m_eAnturaState == AnturaContollerState.REACHINGLETTER)//letter reached, rotate { //swap dest and start Vector3 _v3Temp = m_v3StartPosition; m_v3StartPosition = m_v3Destination; m_v3Destination = _v3Temp; //rotate towards letter m_bRotatingToTarget = true; //set new state m_eAnturaState = AnturaContollerState.TURN_TO_BARK; } else if (m_eAnturaState == AnturaContollerState.TURN_TO_BARK)//now bark { //change animation and play sound //m_oAntura.SetAnimation(m_eAnimationOnLLReached); //m_oAntura.IsBarking = true; m_oAntura.State = m_eAnimationOnLLReached; m_oAntura.DoShout(); ColorTickleConfiguration.Instance.Context.GetAudioManager().PlaySound(Sfx.DogBarking); m_fBarkTimeProgress = 0; //set new state m_eAnturaState = AnturaContollerState.BARKING; } else if (m_eAnturaState == AnturaContollerState.BARKING) //return back { m_bMovingToDestination = true; //m_oAntura.SetAnimation(m_eAnimationOnMoving); //m_oAntura.IsBarking = false; m_oAntura.State = m_eAnimationOnMoving; m_eAnturaState = AnturaContollerState.COMINGBACK; } else if (m_eAnturaState == AnturaContollerState.COMINGBACK) //rotate towards letter again { //swap dest and start Vector3 _v3Temp = m_v3StartPosition; m_v3StartPosition = m_v3Destination; m_v3Destination = _v3Temp; //rotate m_bRotatingToTarget = true; //set new state m_eAnturaState = AnturaContollerState.ROTATION; } else if (m_eAnturaState == AnturaContollerState.ROTATION) //gone back to start { //change animation //m_oAntura.SetAnimation(m_eAnimationOnStandby); m_oAntura.State = m_eAnimationOnStandby; //set new state m_eAnturaState = AnturaContollerState.SLEEPING; } //launch event if (OnStateChanged != null) { OnStateChanged(m_eAnturaState); } }