I need help with AI,Force not working
So I'm new at Unity and Programming, and I'm recreating games to get used to Unity and C#
Everything been going smooth till now, every time I had a problem with my pong game I always found a solution.
But right now the final step to finish the game is adding the AI, but it's not working I've seen thousands of videos, but I just can't figure it out what's wrong with the code
I was hoping that someone could help me.
public float speed;
Rigidbody2D airig;
public Rigidbody2D ball;
private void Start()
{
airig = GetComponent();
}
private void FixedUpdate()
{
Debug.Log(speed);
Debug.Log(ball.velocity.x);
Debug.Log(transform.position.y);
Debug.Log(ball.transform.position.y);
if (ball.velocity.x > 0f) {
if (ball.position.y > transform.position.y)
{
airig.AddForce(Vector2.up * speed) ;
}
}
}
What I think it's wrong is that add force it's not adding force to vector2.up but i don't know how to fix that, that's what I think it's wrong.