Dreamteck / splines

The official Dreamteck Splines for Unity repository
Apache License 2.0
22 stars 2 forks source link

Spline Follower with custom Clip Range loops with offset #13

Closed Kronoxis closed 2 months ago

Kronoxis commented 4 months ago

Issue

See Discord thread

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.

Tests available on test branch

Notes

  1. 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.
  2. The 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