Reputation: 134
I don't quite understand what the 'fraction value means at the end of a lerp statement. I looked at the documentation and the unity scripting API, but my code just doesn't seem to be working. If you could help me figure out what the problem is here I would appreciate it!
Here is my code:
void Awake()
{
StartCoroutine(waitWhileLerp());
}
private IEnumerator waitWhileLerp()
{
while(true)
{
yield return new WaitForSecondsRealtime(lerpSpeed);
transform.position = Vector3.Lerp(transform.position, PathfindingCalc(screenXRadius, screenYRadius, agenPathfinderRange), lerpSpeed * Time.deltaTime);
Debug.Log(transform.position = (PathfindingCalc(screenXRadius, screenYRadius, agenPathfinderRange)));
}
}
private Vector3 PathfindingCalc(float maxXAbsalute, float maxYAbsalute, float range)
{
float x, y;
x = Random.Range(transform.position.x - range, transform.position.x + range);
y = Random.Range(transform.position.y - range, transform.position.y + range);
x = Mathf.Clamp(x, -screenXRadius, screenXRadius);
y = Mathf.Clamp(y, -screenYRadius, screenYRadius);
return new Vector3(x, y, 0);
}
Upvotes: 1
Views: 202
Reputation: 714
lerp interpolates between two points, so it finds a point in between them and goes towards it. The third field is used to calculate that point: if the distance between your position and the target is 100 and you put fraction at .3 you will go from your position towards 30. it should be between 0 and 1 (it is a fraction). i don't think that converting with timedeltatime helps but i'm not sure about that.
Upvotes: 2