You're welcome, thanks for reporting!
RemDust wrote
1/ the fix seems to work really well. I'll let you know how stable it is moving forward.
Very glad to hear!
RemDust wrote2/ Using Rigidbody2D root motion is easy in the X axis, but I'm not too sure if I'm using it well on Y axis, mixing gravity and root motion animation seems like a arguably bad idea ^^
I don't see a problem yet as it's just adding a root motion delta to the position of the rigidbody via
rigidBody2D.MovePosition(new Vector2(transform.position.x, transform.position.y) + rigidbodyDisplacement);
So gravity should apply it's acceleration, and the rootmotion script should move the object an additional rootmotion-delta, both summing up additively. Admittedly I haven't thought this through completely though, did you encounter any problems?
RemDust wrote3/ Delta compensation is absolutely great ! I have just started playing with it but I think having an option to separate extrapolation on X and Y axis could be useful :
Good point! This is missing in the method AdjustRootMotionToDistance
in the root motion script. I will add it to both SkeletonRootMotionBase.AdjustRootMotionToDistance
and the RootMotionDeltaCompensation
example component.
For instance, I have this case where the enemy jumps from a distance towards the player. Right now Delta Compensation overrides the Y jump component (as enemy and player are on the same ground) so he looks like he is sliding towords the player.
If your animation starts at Y=0, has its high point at Y=1 and ends at Y=0 again, delta compensation of both X and Y should lead to the jump being adjusted only on the X axis and nothing changed on Y. I receive this at a local test setup. I wonder why you see a horizontal slide with Y motion being removed.
RemDust wrote
-> I guess enemy should use X Delta compensation but not Y, at least not right away. Actually in this case I think it would make sense that the enemy ignore Y Delta Compensation for the first part of the jump, where he is going upward and trigger Y compensation while he's going down.
Please note that delta compensation will scale your remaining animation so that the distance of position(now)
to position(last_frame)
fits the desired vector. So when you're at the first frame, it will scale the X and Y portions of the delta so that it reaches the target end point instead of the unscaled endpoint. There will be problems however if your target endpoint is at different Y and your animation does not change Y position from start to end, because no scaling can change a delta of 0.0 to e.g. 1.8. The easiest solution for this problem would be to create a jump animation that e.g. has an arc of Y values like: 0, 2, 1
. This way the whole arc will be scaled, when e.g. delta compensating the jump to land at Y=3 it will become 0, 6, 3
. Unfortunately this scaling solution does not yet solve the case for jumping down to e.g. -1 while using an upward animation, because it would then mirror the arc to a negative 0, -2, -1. Solutions to this problem could be
- a) to enable delta-compensation later as you described, at the apex of the arc when moving downwards (although this will then look wrong, scaling only the downward half of the arc)
- b) an additional more complex delta compensation method to allow for such adjustment automatically.
I have added functionality to separately apply delta compensation only for the X or Y component.
changelog.md wroteRoot 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.
A commit has just been pushed to the 3.8 branch and a new unitypackage is available for download here as usual:
esotericsoftware.com/spine-unity-download
It will be integrated in the 4.0-beta branch soon.