Created
May 11, 2020 15:12
-
-
Save korchoon/0d76190dba29ccc9e251bbe3b7166aae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerator Interpolate(float3 p0, float3 p1) { | |
var maxProgress = 0f; | |
var segmentDelta = p1 - p0; | |
var len = math.distance(p1, p0); | |
var fwDelta = fwDeltaLen / len; | |
var segmentDir = math.normalize(segmentDelta); | |
while (true) { | |
float3 position = transform.position; | |
var progress = fwDelta + math.dot(position - p0, segmentDir) / len; | |
progress = math.clamp(progress, 0f, 1f); | |
if (progress > maxProgress) | |
maxProgress = progress; | |
_projectedTarget = math.lerp(p0, p1, maxProgress); | |
if (maxProgress == 1f) | |
break; | |
yield return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment