Vector2 paddleToBallVector;
void Start ()
{
paddleToBallVector = transform.position - paddle1.transform.position;
}
// Update is called once per frame
void Update ()
{
Vector2 paddlePos = new Vector2(paddle1.transform.position.x, paddle1.transform.position.y);
transform.position = paddlePos + paddleToBallVector;
}
Can’t understand why ball sticks to the paddle… for example transform. position = (2,5) and padlle1.transform.position is (4.1), so paddleToBallVector equals to (2-4,5-1) = (-2,4).
paddlePos vector is (4,1), coz the paddle position is (4,1). So the question is why ball sticks to paddle if transform.position = paddlePos(4,1) + paddleToBallVector(-2,4) = (2,5)? (2,5) coordinates are not near the paddle position (4,1) … i’m getting crazy xD can’t find where i am mistaken.
And the second question is: why can’t we use this code to stick the ball?
transform.position = paddle1.transform.position + Vector2.up