Closed danzel closed 9 years ago
Sorry, was wrong about the fraction. The other part is definitely a bug though. Corrected code:
if (d < minDistance) {
minDistance = d;
pathDistance = segmentLengthTotal + segmentProjection;
}
segmentLengthTotal += segmentLength;
Do you mean that instead of
segmentLengthTotal += segmentLength;
if (!(d < minDistance)) continue;
minDistance = d;
pathDistance = segmentLengthTotal + segmentProjection;
you would expect it to be
if (d < minDistance) {
minDistance = d;
pathDistance = segmentLengthTotal + segmentProjection;
}
segmentLengthTotal += segmentLength;
which you post as the corrected code?
Because if so, both are equivalent.
They are not equivalent.
segmentLengthTotal += segmentLength; //previous + segmentlength
if (!(d < minDistance)) continue;
minDistance = d;
pathDistance = segmentLengthTotal + segmentProjection; //previous + segmentlength + projected
if (d < minDistance) {
minDistance = d;
pathDistance = segmentLengthTotal + segmentProjection; //previous + projected
}
segmentLengthTotal += segmentLength;
The current code counts segmentLength before progressing over that segment (unless I'm missing something)
You are absolutely right, and that's what I get for reviewing these things late at night. I'll take care of it.
Thanks!
Fixed on commit 6517eba
Awesome
Specifically this part: https://github.com/ricardojmendez/UnitySteer/blob/development/Vector3Pathway.cs#L205-L208
We add the whole segment length even if we are only part way along this segment segmentProjection is a fraction (0-1) along the length of the segment, so we need to multiply it by this segments length.
I think this is what it should look like: