I’m learning Unity and decided to make Pong since it’s pretty easy to make and I’d learn some stuff doing it. Right now the enemy paddle just uses Lerp to follow the balls Y position. I want to make it so there’s a small delay for this, like the enemy paddle is always going towards the position of the ball .2 seconds ago. I just have no idea how to do this. I’m using C#.
You can delay code using Coroutines, take a look at Unity - Scripting API: Coroutine
So, for example, you could do this:
void Start() {
StartCoroutine(WaitAndFollow());
}
IEnumerator WaitAndFollow() {
yield return new WaitForSeconds(0.2f);
// Execute code for following ball's position
StartCoroutine(WaitAndFollow());
}