Skip to content

Commit b48577b

Browse files
committed
bugfix: respect blend time when backing out of a heterogeneous blend
1 parent f4272b2 commit b48577b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

com.unity.cinemachine/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414
- Decollider would sometimes cause camera to slip inside cracks between adjacent colliders.
1515
- The Deoccluder failed to reset its state when initially enabled, and sometimes caused small spurious camera rotations.
1616
- Fixed the Radial Axis input axis in the CinemachineOrbitalFollow component to map to the y axis.
17+
- Desired blend time is respected when interrupting blends with heterogeneous blend-in and blend-out times.
1718

1819
### Changed
1920
- Added delayed processing to near and far clip plane inspector fields for the CinemachineCamera lens.

com.unity.cinemachine/Runtime/Core/CameraBlendStack.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public void UpdateRootFrame(
234234
if (activeCamera != outgoingCamera)
235235
{
236236
bool backingOutOfBlend = false;
237+
float backingOutPercentCompleted = 0;
237238
float duration = 0;
238239

239240
// Do we need to create a game-play blend?
@@ -246,6 +247,8 @@ public void UpdateRootFrame(
246247
{
247248
// Are we backing out of a blend-in-progress?
248249
backingOutOfBlend = frame.Source.CamA == activeCamera && frame.Source.CamB == outgoingCamera;
250+
if (backingOutOfBlend && frame.Blend.Duration > kEpsilon)
251+
backingOutPercentCompleted = frame.Blend.TimeInBlend / frame.Blend.Duration;
249252

250253
frame.Source.CamA = outgoingCamera;
251254
frame.Source.BlendCurve = blendDef.BlendCurve;
@@ -289,11 +292,15 @@ public void UpdateRootFrame(
289292
if (backingOutOfBlend)
290293
{
291294
snapshot = true; // always use a snapshot for this to prevent pops
292-
duration = frame.Blend.TimeInBlend;
295+
var adjustedDuration = frame.Blend.TimeInBlend;
293296
if (nbs != null)
294-
duration += nbs.Blend.Duration - nbs.Blend.TimeInBlend;
297+
adjustedDuration += nbs.Blend.Duration - nbs.Blend.TimeInBlend;
295298
else if (frame.Blend.CamA is SnapshotBlendSource sbs)
296-
duration += sbs.RemainingTimeInBlend;
299+
adjustedDuration += sbs.RemainingTimeInBlend;
300+
301+
// In the event that the blend times in the different directions are different,
302+
// don't make the blend longer than it would otherwise have been
303+
duration = Mathf.Min(duration * backingOutPercentCompleted, adjustedDuration);
297304
}
298305

299306
// Chain to existing blend

0 commit comments

Comments
 (0)