void Update() { antura.IsAngry = angry; antura.SetWalkingSpeed(walkSpeed); if (doTransition) { doTransition = false; antura.State = targetState; } if (doBurp) { doBurp = false; antura.DoBurp(); } if (doBite) { doBite = false; antura.DoBite(); } if (doShout) { doShout = false; antura.DoShout(); } if (doSniff) { doSniff = false; antura.DoSniff(); } if (onJumpStart) { onJumpStart = false; antura.OnJumpStart(); } if (onJumpMiddle) { onJumpMiddle = false; antura.OnJumpMaximumHeightReached(); } if (onJumpGrab) { onJumpGrab = false; antura.OnJumpGrab(); } if (onJumpEnd) { onJumpEnd = false; antura.OnJumpEnded(); } if (doCharge) { doCharge = false; antura.DoCharge(null); } if (doSpitOpen) { doSpitOpen = false; antura.DoSpit(true); } if (doSpitClosed) { doSpitClosed = false; antura.DoSpit(false); } if (onSlipStart) { onSlipStart = false; antura.OnSlipStarted(); } if (onSlipEnd) { onSlipEnd = false; antura.OnSlipEnded(); } }
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; }