void Update() { if (path != null) { var target = path[currentNode]; var distance = target - transform.position; float distanceSqrMagnitude = distance.sqrMagnitude; distance.y = 0; if (distanceSqrMagnitude < 2) { // reached ++currentNode; if (currentNode >= path.Count) { animationController.State = AnturaAnimationStates.idle; path = null; } } else { if (isSniffing) { return; } randomSniffTime -= Time.deltaTime; if (randomSniffTime < 0) { randomSniffTime = UnityEngine.Random.Range(3, 6); isSniffing = true; speed = 0; animationController.DoSniff(() => { isSniffing = false; }); Audio.AudioManager.I.PlaySound(Sfx.DogSnorting); } else { distance.Normalize(); speed = Mathf.Min(12, speed + 20 * Time.deltaTime); //transform.position += distance * Mathf.Abs(Vector3.Dot(distance, transform.forward)) * speed * Time.deltaTime; Vector3 direction = Vector3.Slerp(distance, transform.forward, Mathf.Sqrt(distanceSqrMagnitude) / 2); transform.position += direction * speed * Time.deltaTime; GameplayHelper.LerpLookAtPlanar(transform, target, Time.deltaTime * 4); } } } }
void Update() { var distance = target - transform.position; distance.y = 0; if (IsAnturaTime) { if (nextAnturaBarkTimer <= 0) { PrepareNextAnturaBark(); TakeMeHomeConfiguration.Instance.Context.GetAudioManager().PlaySound(Sfx.DogBarking); } else { nextAnturaBarkTimer -= Time.deltaTime; } } if (distance.sqrMagnitude < 0.1f) { transform.position = target; // reached //if (IsAnturaTime) // SetRandomTarget(); if (IsAnturaTime) { //SetAnturaTime (false, initialPosition); GetComponent <AnturaAnimationController>().State = AnturaAnimationStates.sitting; //GetComponent<Antura> ().SetAnimation (AnturaAnim.SitBreath); StartCoroutine(waitAndReturn(1)); } } else { distance.Normalize(); transform.position += distance * Vector3.Dot(distance, transform.forward) * ANTURA_SPEED * Time.deltaTime; GameplayHelper.LerpLookAtPlanar(transform, target, Time.deltaTime * 3); } }
void Update() { var distance = target - transform.position; distance.y = 0; if (IsAnturaTime) { if (nextAnturaBarkTimer <= 0) { PrepareNextAnturaBark(); antura.DoShout(() => { AudioManager.I.PlaySound(Sfx.DogBarking); }); } else { nextAnturaBarkTimer -= Time.deltaTime; } } if (distance.sqrMagnitude < 0.1f) { // reached if (IsAnturaTime) { SetRandomTarget(); } } else { distance.Normalize(); transform.position += distance * Mathf.Abs(Vector3.Dot(distance, transform.forward)) * ANTURA_SPEED * Time.deltaTime; GameplayHelper.LerpLookAtPlanar(transform, target, Time.deltaTime * 4); } }
void Update() { if (isSliping) { transform.position += lastVelocity * Time.deltaTime; var velMagnitude = lastVelocity.magnitude; if (velMagnitude > 1) { lastVelocity -= 10 * lastVelocity.normalized * Time.deltaTime; } else { lastVelocity = Vector3.Lerp(lastVelocity, Vector3.zero, 4 * Time.deltaTime); } if (lastVelocity.magnitude < 0.2f) { isSliping = false; runningTime = 0; AnimationController.OnSlipEnded(); } return; } if (!IsSleeping && !IsJumping && target != null) { var distance = target.position - transform.position; distance.y = 0; var distMagnitude = distance.magnitude; float speed = 0; if (!IsNearTargetPosition) { wasNearPosition = false; float speedFactor = Mathf.Lerp(0, 1, distMagnitude / 10); speed = Mathf.Lerp(WALK_SPEED, RUN_SPEED, speedFactor) * Mathf.Lerp(0, 1, distMagnitude); AnimationController.SetWalkingSpeed(speedFactor); if (speedFactor > 0.75f) { runningTime += Time.deltaTime; } else { if (runningTime > 1.3f && Excited) { // Slip! runningTime = 0; isSliping = true; AnimationController.OnSlipStarted(); Update(); return; } runningTime = 0; } } else { wasNearPosition = true; } if (speed > 0.05f) { AnimationController.State = AnturaAnimationStates.walking; if (AnimationController.IsAnimationActuallyWalking) { distance.Normalize(); var steeringMovement = transform.forward * speed * Time.deltaTime; var normalMovement = distance * Mathf.Abs(Vector3.Dot(distance, transform.forward)) * speed * Time.deltaTime; transform.position += Vector3.Lerp(steeringMovement, normalMovement, 10.0f * Vector3.Dot(transform.forward.normalized, distance.normalized)); GameplayHelper.LerpLookAtPlanar(transform, target.position, Time.deltaTime * 2); } } else { var dot = Mathf.Max(0, Vector3.Dot(target.forward.normalized, transform.forward.normalized)); if (rotatingBase) { Quaternion targetRotation; transform.SetParent(rotatingBase); if (rotateAsTarget) { targetRotation = target.rotation * rotatingBase.rotation; } else { targetRotation = rotatingBase.rotation; } transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 4); } else { if (rotateAsTarget) { transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation, Time.deltaTime * 4 * (0.2f + 0.8f * dot)); } if ((!rotateAsTarget || dot > 0.9f) && AnimationController.State == AnturaAnimationStates.walking) { AnimationController.State = AnturaAnimationStates.idle; } } } } lastVelocity = (transform.position - lastPosition) / Time.deltaTime; lastPosition = transform.position; }
public void LerpLookAt(Vector3 position, float t) { GameplayHelper.LerpLookAtPlanar(transform, position, t); }
public void LookAt(Vector3 position) { GameplayHelper.LerpLookAtPlanar(transform, position, 1); }