Pong game, computer paddle shaking

Im making a pong game. I seem to be having an issue with the computer paddle. Its only a small problem but its kinda annoying. The paddle moves fine but it shakes. Is there an issue with the way im moving the paddle. Code below. Thank you.

using UnityEngine;
using System.Collections;

public class ComputerControls : MonoBehaviour {

	public GameObject myBall;
	public GameObject paddle;

	void FixedUpdate () {

		if(myBall.transform.position.y > paddle.transform.position.y)
			paddle.transform.position = new Vector2(paddle.transform.position.x, paddle.transform.position.y +1 * Time.deltaTime * 3);
		else
			paddle.transform.position = new Vector2(paddle.transform.position.x, paddle.transform.position.y -1 * Time.deltaTime * 3);
		
	}
}

Does it shake vertically? The issue I can imagine happening here is that you’re checking the transform’s y position against the ball’s y position directly, these are very precise numbers and it’s difficult to get them to match. By moving your paddle by an arbitrary speed (y-1 * 3 * dT) in the direction of the ball it is going to OVERSHOOT.

Then the next frame it jumps up to compensate. Then back down. You need to stabalize it so that if the distance between the ball’s y and the paddle’s y is within your speed range it doesn’t overshoot.

To illustrate the point, imagine the ball is at y 5.15. The paddle is at y 5.14. Your script runs, it passes, and now it’s moving the paddle up more than 0.01 units. The process repeats in the other direction.

You can also solve this by using the MoveTowards function (Unity - Scripting API: Vector3.MoveTowards) which has built in correction.

Does it have a rigidbody attached? Is that rigidbody marked IsKinematic?

It sounds like the shake is probably the paddle trying to move under physics, but you’re forcing it’s transform position, then physics is affecting it, then you are forcing it’s transform.

Make sure you set the rigidbody to IsKinematic