public void update() { Vector2 cameraPos = transform.position; Vector2 objectToFollowPos = ObjectToFollow.position; float halfWidth = _camera.bounds.width / 2.0f; float halfHeight = _camera.bounds.height / 2.0f; if (!Deadzone.Contains(objectToFollowPos)) { cameraPos = Lerps.ease(EaseType.QuadInOut, cameraPos, objectToFollowPos, SmoothTime, 1.0f); // cameraPos = Lerps.lerpDamp(cameraPos, objectToFollowPos, SmoothSpeed); } if (cameraPos.X - halfWidth < MapEdge.Min.X) { cameraPos.X = MapEdge.Min.X + halfWidth; } if (cameraPos.Y - halfHeight < MapEdge.Min.Y) { cameraPos.Y = MapEdge.Min.Y + halfHeight; } if (cameraPos.X + halfWidth > MapEdge.Max.X) { cameraPos.X = MapEdge.Max.X - halfWidth; } if (cameraPos.Y + halfHeight > MapEdge.Max.Y) { cameraPos.Y = MapEdge.Max.Y - halfHeight; } transform.position = cameraPos; }
public override void UpdateValue(float elapsedTime) { this.TweenTarget.TweenedValue = Lerps.Ease( this.EaseType, this.FromValue, this.ToValue, elapsedTime, this.Duration); }
/// <summary>Gets the new (interpolated) camera orbit position.</summary> /// <param name="orbitAngles">Angle to orbit</param> /// <param name="deltaTime"></param> /// <returns></returns> public Vector3 GetOrbitPosition(Vector3 orbitAngles, float deltaTime) { //get new camera position (this can/will change the distance from the target, but it is interpolated seperately next anyway) Vector3 desiredPos = GetDesiredOrbitPositionFromAngles(orbitAngles); Vector3 newCamPos = locomotion.MoveCameraInterpolated(desiredPos, camParams.orbitSpeed, deltaTime); //interpolate distance from target separately Vector3 newOffset = newCamPos - followTarget.transform.position; //convert new cam position back to a world space offset from follow target float newDistance = Lerps.Smootherstep((cam.transform.position - followTarget.transform.position).magnitude, camParams.desiredOrbitDistance, camParams.orbitSpeedDistance * deltaTime); //interpolate between current offset distance and desired distance return(followTarget.transform.position + newOffset.normalized * newDistance); //scale normalised offset by new distance and convert back to world position }
public Vector3 GetTargetFollowPosition(float deltaTime, float virtualCameraSphereRadius) { //get desired offset based on whether target is moving towards or away from camera. If we add more camera-target orientation states, //will need to do this a better way Vector3 desiredOffset; float followSpeedHorz; float followSpeedVert; float followSpeedDistance; if (stateController.GetOrientationState() == CameraTargetOrientationState.TowardsCamera && camParams.allowMoveTowardsCamera) { desiredOffset = camParams.desiredFrontOffset; followSpeedHorz = camParams.frontFollowSpeedOrientation; followSpeedVert = camParams.frontFollowSpeedHeight; followSpeedDistance = camParams.frontFollowSpeedDistance; } else //moving away from camera { desiredOffset = camParams.desiredOffset; followSpeedHorz = camParams.followSpeedOrientation; followSpeedVert = camParams.followSpeedHeight; followSpeedDistance = camParams.followSpeedDistance; } //get desired height offset based on follow height mode if (camParams.followHeightMode == FollowHeightMode.AboveGround) { desiredOffset.y = GetDesiredHeightAboveGroundOffset(virtualCameraSphereRadius); } //get desired position from offset Vector3 desiredPos = GetDesiredFollowPositionWorld(desiredOffset); //shorten follow distance if necessary desiredPos = occlusionAvoidance.ShortenFollowDistanceToAvoidRearOcclusion(desiredPos, virtualCameraSphereRadius); //increase follow speed if avoiding occlusion if (camParams.avoidFollowTargetOcclusion) { float occlusionSpeedIncrease = occlusionAvoidance.GetOcclusionFollowSpeedIncrease(); followSpeedHorz += occlusionSpeedIncrease; followSpeedVert += occlusionSpeedIncrease; } //interpolate between current and desired positions Vector3 newCamPos = locomotion.MoveCameraInterpolated(desiredPos, followSpeedHorz, followSpeedVert, deltaTime); //interpolate distance from target separately float desiredDistance = desiredOffset.magnitude; Vector3 newOffset = newCamPos - followTarget.transform.position; //convert new cam position back to a world space offset from follow target float newDistance = Lerps.Smootherstep(newOffset.magnitude, desiredDistance, followSpeedDistance * deltaTime); //interpolate between current offset distance and desired distance return(followTarget.transform.position + (newOffset.normalized * newDistance)); //scale normalised offset by new distance and convert back to world position }
protected override void UpdateValue() { var next = Lerps.Ease(_easeType, _fromValue, _toValue, _elapsedTime, _duration); // XXX: hack for rounding // var delta = _toValue - next; // if (Math.Abs(delta.X) < 1f && Math.Abs(delta.Y) < 1f) { // next = _toValue; // } _target.SetTweenedValue(next); }
private void ValueChange() { //if(ScaleRef.Value < 20) //{ // tween?.Complete(); // tween = transform.DOPunchScale(Vector3.one * ScaleRef.Value.Clamp(0.5f, 20), ScaleSpeed, 7); // tween.onComplete -= OnComplete; // tween.onComplete += OnComplete; //} //else { tween?.Complete(); tween = transform.DOScale(Vector3.one * ScaleRef.Value.Clamp(0.5f, 20), 1); } WorldSettings.GameRadius = Lerps.Lerp(35f, 60f, ScaleRef.Value.Clamp(0, 2)); }
/// <summary> /// the most common type of transition seems to be one that ticks progress from 0 - 1. This method takes care of that for you /// if your transition needs to have a _progress property ticked after the scene loads. /// </summary> /// <param name="duration">duration</param> /// <param name="reverseDirection">if true, _progress will go from 1 to 0. If false, it goes form 0 to 1</param> public IEnumerator tickEffectProgressProperty(Effect effect, float duration, EaseType easeType = EaseType.ExpoOut, bool reverseDirection = false) { var start = reverseDirection ? 1f : 0f; var end = reverseDirection ? 0f : 1f; var progressParam = effect.Parameters["_progress"]; var elapsed = 0f; while (elapsed < duration) { elapsed += Time.deltaTime; var step = Lerps.ease(easeType, start, end, elapsed, duration); progressParam.SetValue(step); yield return(null); } }
public override IEnumerator onBeginTransition() { yield return(null); var elapsed = 0f; while (elapsed < duration) { elapsed += Time.deltaTime; _renderScale = Lerps.ease(scaleEaseType, maxScale, minScale, elapsed, duration); _renderRotation = Lerps.ease(rotationEaseType, minRotation, maxRotation, elapsed, duration); yield return(null); } // load up the new Scene yield return(Core.startCoroutine(loadNextScene())); // dispose of our previousSceneRender. We dont need it anymore. previousSceneRender.Dispose(); previousSceneRender = null; yield return(Coroutine.waitForSeconds(delayBeforeMaskOut)); elapsed = 0f; while (elapsed < duration) { elapsed += Time.deltaTime; _renderScale = Lerps.ease( EaseHelper.oppositeEaseType(scaleEaseType), minScale, maxScale, elapsed, duration); _renderRotation = Lerps.ease( EaseHelper.oppositeEaseType(rotationEaseType), maxRotation, minRotation, elapsed, duration); yield return(null); } transitionComplete(); }
/// <summary> /// animates the letterbox in /// </summary> /// <returns>The in.</returns> /// <param name="letterboxSize">Letterbox size.</param> /// <param name="duration">Duration.</param> /// <param name="easeType">Ease type.</param> public IEnumerator animateIn(float letterboxSize, float duration = 2, EaseType easeType = EaseType.ExpoOut) { // wait for any current animations to complete while (_isAnimating) { yield return(null); } _isAnimating = true; var elapsedTime = 0f; while (elapsedTime < duration) { elapsedTime += Time.deltaTime; this.letterboxSize = Lerps.ease(easeType, 0, letterboxSize, elapsedTime, duration); yield return(null); } _isAnimating = false; }
public override IEnumerator OnBeginTransition() { yield return(null); // load up the new Scene yield return(Core.StartCoroutine(LoadNextScene())); var elapsed = 0f; while (elapsed < FadeDuration) { elapsed += Time.DeltaTime; _color = Lerps.Ease(FadeEaseType, ref _fromColor, ref _toColor, elapsed, FadeDuration); yield return(null); } TransitionComplete(); }
public override IEnumerator onBeginTransition() { yield return(null); // load up the new Scene yield return(Core.startCoroutine(loadNextScene())); var elapsed = 0f; while (elapsed < duration) { elapsed += Time.deltaTime; _destinationRect = Lerps.ease(transitionEaseType, ref _textureBounds, ref _finalRenderRect, elapsed, duration); yield return(null); } transitionComplete(); }
public IEnumerator TickEffectProgressProperty( IProgressEffect effect, float duration, EaseType easeType = EaseType.ExpoOut, bool reverseDirection = false) { var start = reverseDirection ? 1f : 0f; var end = reverseDirection ? 0f : 1f; var startAt = DateTime.Now; while ((DateTime.Now - startAt).TotalSeconds < duration) { var elapsed = (float)(DateTime.Now - startAt).TotalSeconds; var step = Lerps.Ease(easeType, start, end, elapsed, duration); effect.Progress = step; yield return(null); } }
public override IEnumerator onBeginTransition() { // create a single pixel texture of our fadeToColor _overlayTexture = Graphics.createSingleColorTexture(1, 1, fadeToColor); var elapsed = 0f; while (elapsed < fadeOutDuration) { elapsed += Time.deltaTime; _color = Lerps.ease(fadeEaseType, ref _toColor, ref _fromColor, elapsed, fadeOutDuration); yield return(null); } // load up the new Scene yield return(Core.startCoroutine(loadNextScene())); // dispose of our previousSceneRender. We dont need it anymore. previousSceneRender.Dispose(); previousSceneRender = null; yield return(Coroutine.waitForSeconds(delayBeforeFadeInDuration)); elapsed = 0f; while (elapsed < fadeInDuration) { elapsed += Time.deltaTime; _color = Lerps.ease( EaseHelper.oppositeEaseType(fadeEaseType), ref _fromColor, ref _toColor, elapsed, fadeInDuration); yield return(null); } transitionComplete(); _overlayTexture.Dispose(); }
/// <summary> /// animates the flash /// </summary> /// <returns>The in.</returns> /// <param name="letterboxSize">Letterbox size.</param> /// <param name="duration">Duration.</param> /// <param name="easeType">Ease type.</param> public IEnumerator animate(float fadeDuration, EaseType easeType = EaseType.SineOut) { // wait for any current animations to complete while (_isAnimating) { yield return(null); } flashIntensity = 1.0f; _isAnimating = true; var elapsedTime = 0f; while (elapsedTime < fadeDuration) { elapsedTime += Time.deltaTime; flashIntensity = Lerps.ease(easeType, 1, 0, elapsedTime, fadeDuration); yield return(null); } _isAnimating = false; }
public override IEnumerator OnBeginTransition() { yield return(null); var elapsed = 0f; while (elapsed < Duration) { elapsed += Time.DeltaTime; _renderScale = Lerps.Ease(ScaleEaseType, MaxScale, MinScale, elapsed, Duration); _renderRotation = Lerps.Ease(RotationEaseType, MinRotation, MaxRotation, elapsed, Duration); yield return(null); } // load up the new Scene yield return(Core.StartCoroutine(LoadNextScene())); // dispose of our previousSceneRender. We dont need it anymore. PreviousSceneRender.Dispose(); PreviousSceneRender = null; yield return(Coroutine.WaitForSeconds(DelayBeforeMaskOut)); elapsed = 0f; while (elapsed < Duration) { elapsed += Time.DeltaTime; _renderScale = Lerps.Ease(EaseHelper.OppositeEaseType(ScaleEaseType), MinScale, MaxScale, elapsed, Duration); _renderRotation = Lerps.Ease(EaseHelper.OppositeEaseType(RotationEaseType), MaxRotation, MinRotation, elapsed, Duration); yield return(null); } TransitionComplete(); }
public override IEnumerator OnBeginTransition() { var startAt = DateTime.Now; while ((DateTime.Now - startAt).TotalSeconds < this.FadeOutDuration) { var elapsed = (float)(DateTime.Now - startAt).TotalSeconds; this.color = Lerps.Ease( this.FadeEaseType, ref this.fromColor, ref this.toColor, elapsed, this.FadeOutDuration); yield return(null); } this.SetNextScene(); yield return(DefaultCoroutines.Wait(this.DelayBeforeFadeInDuration)); startAt = DateTime.Now; while ((DateTime.Now - startAt).TotalSeconds < this.FadeInDuration) { var elapsed = (float)(DateTime.Now - startAt).TotalSeconds; this.color = Lerps.Ease( EaseHelper.OppositeEaseType(this.FadeEaseType), ref this.toColor, ref this.fromColor, elapsed, this.FadeInDuration); yield return(null); } this.TransitionComplete(); }
public override IEnumerator OnBeginTransition() { yield return(null); var startAt = DateTime.Now; while ((DateTime.Now - startAt).TotalSeconds < this.Duration) { var elapsed = (float)(DateTime.Now - startAt).TotalSeconds; this.destinationRect = Lerps.Ease( this.TransitionEaseType, this.PreviousSceneRender.Bounds, this.finalRenderRect, elapsed, this.Duration); yield return(null); } this.SetNextScene(); startAt = DateTime.Now; while ((DateTime.Now - startAt).TotalSeconds < this.Duration) { var elapsed = (float)(DateTime.Now - startAt).TotalSeconds; this.destinationRect = Lerps.Ease( this.TransitionEaseType, this.finalRenderRect, this.PreviousSceneRender.Bounds, elapsed, this.Duration); yield return(null); } this.TransitionComplete(); }
public Vector3 MoveCameraInterpolated(Vector3 desiredPos, float horizontalMoveSpeed, float verticalMoveSpeed, float deltaTime) { return(Lerps.Smootherstep(cam.transform.position, desiredPos, horizontalMoveSpeed * deltaTime, verticalMoveSpeed * deltaTime)); }
public static float Lerp(this float start, float end, float time, bool clamp = false) => Lerps.Lerp(start, end, time, clamp);
private void OffsetFromTarget(ref Vector3 newPos) { Vector3 desiredPos; //Get desired camera position based on state switch (state) { case State.TargetMovingTowardsCamera: Vector3 frontOffset = new Vector3(desiredOffset.x, desiredOffset.y, Mathf.Abs(desiredOffset.z)); desiredPos = followTargetPos + (worldSpaceOffset ? frontOffset : followTarget.transform.TransformDirection(frontOffset)); break; case State.FollowingTarget: default: if (worldSpaceOffset) { desiredPos = AvoidCollision(followTargetPos + desiredOffset); } else { desiredPos = AvoidCollision(followTargetPos + followTarget.transform.TransformDirection(desiredOffset)); } break; } //Add cam whisker offset, if using if (useCamWhiskers) { desiredPos += CamWhiskersFromTarget(); } //do not move camera if target is within desired distance and within screen deadzones /* * float camTargetDistance = Vector3.Distance(camPos, followTargetPos); * if (camTargetDistance > minDistanceFromTarget && camTargetDistance < desiredOffsetDistance * && cam.IsWithinDeadzone(followTargetPos, followDeadzoneX, followDeadzoneX, followDeadzonePlusY, followDeadzoneNegativeY)) * { * Debug.Log("target within desired distance and screen deadzones!"); * desiredPos = camPos; * } */ //Interpolate between current camera position and desired position to find new position; clamp if outside min/max distances if (camPos != desiredPos) { //newPos = lerpOffset ? Vector3.SmoothDamp(camPos, desiredPos, ref smoothdampVelocity, 1f / offsetLerpSpeed) : desiredPos; float smoothTime = 1 / offsetLerpSpeed; newPos = lerpOffset ? Lerps.SmoothDampSeparateAxisSeparateY(camPos, desiredPos, ref smoothdampVelocity, smoothTime, smoothTime * 5, smoothTime, smoothTime, Time.deltaTime) : desiredPos; //Clamp newPos to min and max distances. //This causes camera to orbit around target at min distance, which is cool float newPosTargetSqrDist = (followTargetPos - newPos).sqrMagnitude; Vector3 targetToNewPosUnit = (newPos - followTargetPos).normalized; if (newPosTargetSqrDist < sqrMinDistanceFromTarget) { newPos = followTargetPos + (targetToNewPosUnit * minDistanceFromTarget); } else if (newPosTargetSqrDist > sqrMaxDistanceFromTarget) { newPos = followTargetPos + (targetToNewPosUnit * maxDistanceFromTarget); } } }
protected override void UpdateValue() { (this as ITweenTarget <float>).SetTweenedValue((float)Lerps.Ease(_easeType, _fromValue, _toValue, _elapsedTime, _duration)); }