Pong - beating the AI

As a small starter project, I decided to create my own version of PONG in 2D.

I have created an AI which follows the ball, however this is unbeatable. How would I implement speed, to give the player a winning chance?

using UnityEngine;
using System.Collections;

public class Player2AI : MonoBehaviour {

Transform Ball;

void Start ()
{
Ball = GameObject.Find (“Ball”).transform;
}

void Update ()
{
transform.position = new Vector2(transform.position.x, Ball.position.y);
}
}

You could interpolate the position of the AI transform.
Instead of jumping from transform.position to the ball.position, you can simply use a linear interpolation(LERP), which you can see in this tutorial:

http://unity3d.com/learn/tutorials/modules/beginner/scripting/lerp

1 Like

Thank you! I’ve seen LERP before but I wasn’t sure exactly how it was used!
Much appreciated!