When looping with a clip range on a spline, the SplineUser's position is incorrect. The further the clipTo is from 1, the more noticeable the offset is, especially on short splines. For backwards followers, it is the clipFrom that influences the offset.
Fix
The following line is nonsensical. This line does nothing as long as the clip range is default, as ClipPercent(result) will always equal result. But when the clip range is modified, a percentage difference is substracted from a distance value. This can never be correct.
https://github.com/Dreamteck/splines/blob/62d7a20a3db247ed0abeed925bd2b2d096ab45fd/Assets/Dreamteck/Splines/Components/SplineUser.cs#L845
The intention is to subtract the clipped distance from the moved distance, so that the component can loop and travel the remainder from the other side. I have implemented this using _sampleCollection.CalculateLength.
This fix has not been tested for splines with samplesAreLooped == true . Since the clip range is inverted in that case, I suspect my conditions may not handle it correctly.
Issue
See Discord thread
When looping with a clip range on a spline, the SplineUser's position is incorrect. The further the
clipTo
is from1
, the more noticeable the offset is, especially on short splines. For backwards followers, it is theclipFrom
that influences the offset.Fix
The following line is nonsensical. This line does nothing as long as the clip range is default, as
ClipPercent(result)
will always equalresult
. But when the clip range is modified, a percentage difference is substracted from a distance value. This can never be correct. https://github.com/Dreamteck/splines/blob/62d7a20a3db247ed0abeed925bd2b2d096ab45fd/Assets/Dreamteck/Splines/Components/SplineUser.cs#L845 The intention is to subtract the clipped distance from the moved distance, so that the component can loop and travel the remainder from the other side. I have implemented this using_sampleCollection.CalculateLength
.Tests available on test branch
Notes
samplesAreLooped == true
. Since the clip range is inverted in that case, I suspect my conditions may not handle it correctly.TravelWithOffset
method never handled clipping in the first place. It's likely that similar code should be applied here, using_sampleCollection.CalculateLengthWithOffset
. https://github.com/Dreamteck/splines/blob/62d7a20a3db247ed0abeed925bd2b2d096ab45fd/Assets/Dreamteck/Splines/Components/SplineUser.cs#L871-L872