Hi,
I’m working on PingPong game style. My script for the AI player is working fine. But I want to add feature let him know the place will ball hit it. I add invisible object “PredictLineObject” near AiPlayer so I can use it to give me “PredictHit” values to use it. This is my method I don’t know it will work or not. If you have a better one please write it.
public GameManager _gm;
public GameObject Ball, middleObject, PredictLineObject;
public float speed;
public float BallDistance, AiX, AiZ, BallNum;
public Vector3 ballPlace, PredictHit;
// Update is called once per frame
void Update()
{
BallNum = _gm.GetComponent<GameManager>().BallinMatch;
if (BallNum == 0)
{
Ball = null;
}
else
{
Ball = GameObject.FindGameObjectWithTag("GameBall");
BallDistance = Vector3.Distance(gameObject.transform.position, Ball.transform.position);
ballPlace = new Vector3(transform.position.x, transform.position.y, Ball.transform.position.z);
transform.position = Vector3.Lerp(transform.position, ballPlace, Time.deltaTime * speed);
}
AiX = gameObject.transform.position.x - middleObject.transform.position.x;
AiZ = gameObject.transform.position.z - middleObject.transform.position.z;
}