[unity] Root motion delta compensation now allows to only adjust X or Y components instead of both. See #1876.

This commit is contained in:
Harald Csaszar 2021-04-12 17:31:00 +02:00
parent 7782b01cdf
commit dd7c3b1bcc
3 changed files with 9 additions and 4 deletions

View File

@ -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. * `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. * 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. * 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** * **Changes of default values**
* `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`. * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`.

View File

@ -8,6 +8,8 @@ namespace Spine.Unity.Examples {
protected SkeletonRootMotionBase rootMotion; protected SkeletonRootMotionBase rootMotion;
public Transform targetPosition; public Transform targetPosition;
public int trackIndex = 0; public int trackIndex = 0;
public bool adjustX = true;
public bool adjustY = true;
void Start () { void Start () {
rootMotion = this.GetComponent<SkeletonRootMotionBase>(); rootMotion = this.GetComponent<SkeletonRootMotionBase>();
@ -23,7 +25,7 @@ namespace Spine.Unity.Examples {
void AdjustDelta() { void AdjustDelta() {
Vector3 toTarget = targetPosition.position - this.transform.position; Vector3 toTarget = targetPosition.position - this.transform.position;
rootMotion.AdjustRootMotionToDistance(toTarget, trackIndex); rootMotion.AdjustRootMotionToDistance(toTarget, trackIndex, adjustX, adjustY);
} }
} }
} }

View File

@ -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); Vector2 remainingRootMotion = GetRemainingRootMotion(trackIndex);
if (remainingRootMotion.x == 0) if (remainingRootMotion.x == 0)
remainingRootMotion.x = 0.0001f; remainingRootMotion.x = 0.0001f;
if (remainingRootMotion.y == 0) if (remainingRootMotion.y == 0)
remainingRootMotion.y = 0.0001f; remainingRootMotion.y = 0.0001f;
rootMotionScaleX = distanceToTarget.x / remainingRootMotion.x; if (adjustX)
rootMotionScaleY = distanceToTarget.y / remainingRootMotion.y; rootMotionScaleX = distanceToTarget.x / remainingRootMotion.x;
if (adjustY)
rootMotionScaleY = distanceToTarget.y / remainingRootMotion.y;
} }
public Vector2 GetAnimationRootMotion (Animation animation) { public Vector2 GetAnimationRootMotion (Animation animation) {