From dd7c3b1bccc17ae5b7270b5c2c84ed19199df76c Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 12 Apr 2021 17:31:00 +0200 Subject: [PATCH] [unity] Root motion delta compensation now allows to only adjust X or Y components instead of both. See #1876. --- CHANGELOG.md | 1 + .../Sample Components/RootMotionDeltaCompensation.cs | 4 +++- .../Components/RootMotion/SkeletonRootMotionBase.cs | 8 +++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09638ce64..49c41a2ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -256,6 +256,7 @@ * `BoneFollower` and `BoneFollowerGraphic` components now provide better support for following bones when the skeleton's Transform is not the parent of the follower's Transform. Previously e.g. rotating a common parent Transform did not lead to the desired result, as well as negatively scaling a skeleton's Transform when it is not a parent of the follower's Transform. * URP and LWRP `Sprite` and `SkeletonLit` shaders no longer require `Advanced - Add Normals` enabled to properly cast and receive shadows. It is recommended to disable `Add Normals` if normals are otherwise not needed. * Added an example component `RootMotionDeltaCompensation` located in `Spine Examples/Scripts/Sample Components` which can be used for applying simple delta compensation. You can enable and disable the component to toggle delta compensation of the currently playing animation on and off. + * Root motion delta compensation now allows to only adjust X or Y components instead of both. Adds two parameters to `SkeletonRootMotionBase.AdjustRootMotionToDistance()` which default to adjusting both X and Y as before. The `RootMotionDeltaCompensation` example component exposes these parameters as public attributes. * **Changes of default values** * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`. diff --git a/spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs b/spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs index 7731374ab..c1d9f3530 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs @@ -8,6 +8,8 @@ namespace Spine.Unity.Examples { protected SkeletonRootMotionBase rootMotion; public Transform targetPosition; public int trackIndex = 0; + public bool adjustX = true; + public bool adjustY = true; void Start () { rootMotion = this.GetComponent(); @@ -23,7 +25,7 @@ namespace Spine.Unity.Examples { void AdjustDelta() { Vector3 toTarget = targetPosition.position - this.transform.position; - rootMotion.AdjustRootMotionToDistance(toTarget, trackIndex); + rootMotion.AdjustRootMotionToDistance(toTarget, trackIndex, adjustX, adjustY); } } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs index 699cfb3da..a0b259d78 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs @@ -131,14 +131,16 @@ namespace Spine.Unity { } } - public void AdjustRootMotionToDistance (Vector2 distanceToTarget, int trackIndex = 0) { + public void AdjustRootMotionToDistance (Vector2 distanceToTarget, int trackIndex = 0, bool adjustX = true, bool adjustY = true) { Vector2 remainingRootMotion = GetRemainingRootMotion(trackIndex); if (remainingRootMotion.x == 0) remainingRootMotion.x = 0.0001f; if (remainingRootMotion.y == 0) remainingRootMotion.y = 0.0001f; - rootMotionScaleX = distanceToTarget.x / remainingRootMotion.x; - rootMotionScaleY = distanceToTarget.y / remainingRootMotion.y; + if (adjustX) + rootMotionScaleX = distanceToTarget.x / remainingRootMotion.x; + if (adjustY) + rootMotionScaleY = distanceToTarget.y / remainingRootMotion.y; } public Vector2 GetAnimationRootMotion (Animation animation) {