I want to create a simple pong game with an AI as an enemy. Everything is good until I add the AI movement script to the racket. The problem is as soon as the ball hits the racket it behavs like it has a bounciness 1000 or it got 1000 force. So the ball speed gets suddenly too much.
Here is the code:
using UnityEngine;
using System.Collections;
public class AIMovement : MonoBehaviour {
public GameObject ball;
public float speed;
private Rigidbody2D rb2D;
// Use this for initialization
void Start () {
rb2D = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void FixedUpdate () {
Vector2 move = new Vector2 (ball.transform.position.x, 0.0f);
rb2D.MovePosition (move);
}
}
If I add code from manual the bounce behaves like it should but the movement of the racket behaves like it has 3000 ping.
rb2D.MovePosition(rb2D.position + velocity * Time.fixedDeltaTime);