- Home /
Lerp to where the target was x seconds ago?
I want to store the position of where the target was x seconds ago and Lerp to it. The logic should repeat itself every time the counter reaches 150. I am having issues where the projectile is homing in on the target which is not the intended effect. Please help me execute the above logic.
void Start()
{
counter = 0;
lerpTime = 0;
}
void Update()
{
Shoot();
}
Transform LastKnownPosition(Transform lastPos)
{
float timePos = 0;//Time starts at 0
timePos += Time.deltaTime;//Time will increment
if (timePos >= 2) //if time is equal to 2
{
//grab the position of the target
lastPos.position = target.position;
//reset to 0
timePos = 0;
}
//lock that position
return lastPos;
}
void Shoot()
{
counter++;
lerpTime += Time.deltaTime / timeFrame;
if (counter == 150)
{
currentProjectile = Instantiate(projectile) as GameObject;
move = true;
counter = 0;
}
if (counter < 140)
{
currentProjectile.transform.position = Vector2.Lerp(barrel.transform.position, /*Last Known Position*/, lerpTime);
Debug.DrawLine(barrel.transform.position, target.position);
}
}
Comment
Your answer
Follow this Question
Related Questions
Why does object lerp to above the object it is lerping to? 1 Answer
C# move y position of object not working 2 Answers
How to place the GameObjects in a sequence on the plane 1 Answer
C# - Mathf.Lerp: NullReferenceException: Object reference not set 1 Answer
How to make cubes between 2 point and stick them together? 0 Answers