I want to make a PONG AI that can be beatable. but if i make a AI then either it will be unbeatable or ERROR. please help!!!
Here is the Code: using UnityEngine; using System.Collections;
public class Ai : MonoBehaviour {
Transform Ball;
Transform Enemy;
float step;
public float speed;
Transform midline;
void Start ()
{
Enemy = GameObject.Find ("Ball").transform;
}
void Update ()
{
if (Ball < 0)
{
gameObject.SetActive (false);
}
else
{
gameObject.SetActive (true);
step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position.x, Ball.position.x, step);
}
}
}
I am a beginner. So plz help me.
The simplest way, maybe to throw in some randomness.
Ball.position.x + Random.Range(-100, 100)
And/Or to randomly decrease the speed
for a few milliseconds every now and then
Answer by aceofpack · Feb 15, 2016 at 08:48 PM
The difficulty in pong, from what I remember is when the AI can 'see' the ball. You could do this:
Add a circle to the AI-paddle
Define it's radius based on difficulty level
Detect a collision of the ball with this circle (using Is Trigger)
In the collision trigger code, start moving the AI-paddle towards the ball
Limit the speed of the AI-paddle (can also be based on difficulty)
This will mean the paddle can miss the ball, if it reacts too late as the ball is either moving too fast or the paddle is out of position.
Your answer
Follow this Question
Related Questions
Getting an Object that is not a child to match another objects speed 1 Answer
Making the AI move randomly around the player's last known location 1 Answer
How can I make character accelerate and deccelerate using GetAxis? 0 Answers
Javascript Movement too slow or fast. 1 Answer
NPC move and find 0 Answers