First a general question. Is it better to ask questions in Udemy or GameDev.tv? I’m never quite sure where to put comments and questions. In this case I’m putting it in both.
Now to my coding question…
I wrote the code for this video before I watched Rick (attaching the ball to the paddle) but I did it with Vector3 rather than Vector2. The code works. My question is… is it bad practice to be coding with Vector3 in a 2D project? The advantage, in this particular case, is that I have only one line in Update() rather than 2 lines which might be more efficient. Here’s my code.
public class Ball : MonoBehaviour
{
// config params
// note to self: type "Paddle" is defined by the SCRIPT on paddle, not the name of the game object
[SerializeField] Paddle paddle1;
// state
Vector3 paddleToBallVector;
void Start()
{
paddleToBallVector = transform.position - paddle1.transform.position;
}
void Update()
{
transform.position = paddle1.transform.position + paddleToBallVector;
}
}