I’m creating basically a glorified four-way pong game, so I have four paddles and any number of balls in play. I want the AI paddles to move left and right in their relative coordinates and not have to depend on the global space. I have this code so far to demonstrate what I mean, but it depends on the global coordinate system. I’m trying to get the left, right, and top paddles to work based on the same code.
// If ball is within 70% of the middle of the paddle, decelerate
if (Mathf.Abs(thisTransform.position.x - closestBall.position.x) < 0.7f * (thisTransform.localScale.x / 2)) {
// Decelerate
} else if (closestBall.position.x < thisTransform.position.x) {
thisTransform.Translate(Vector3.right * Time.deltaTime * AIPaddleSpeed);
} else {
thisTransform.Translate(-Vector3.right * Time.deltaTime * AIPaddleSpeed);
}