Pong AI NEED HELP!

Hey guys I’m a bit new to scripting but anyway I’m almost finished a pong game but I’m not doing very well with this AI. It’s a very simple AI I just want the paddle to follow the ball on the y axis but I’m lost on what to script, here’s what I’ve done so far:
#pragma strict

var OpponentPaddle : Transform;
var theBall : Transform;
var ballSpeed : float;

function Update () {
if (theBall.position.y){
OpponentPaddle.position.y;
}
}
Any help appreciated! Thanks in advance

First of all, use code tags please. Secondly, you’d definitely benefit from some tutorials! You’d get your answers much more quickly, and it’s a lot more fun to learn.

This is as simple as assigning a position to your opponent paddel transformation, but let’s make it a bit more fun by using Lerp:

var opponentPaddle : Transform;
var opponentSpeed : float;

var ball : Transform;
var ballSpeed : float;

function Update () {
    var targetPosition : Vector3 = new Vector3(opponentPaddle.x, ball.y, 0f);

    opponentPaddle.position = Vector3.Lerp(opponentPaddle.position, targetPosition, Time.deltaTime * opponentSpeed);
}
1 Like

Officer Doofy is on the case! :smile:

1 Like