Why ball sticks to paddle?

 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

Hi Alexey,

Welcome to our community! :slight_smile:

Where did you get the values from? In your code, the values of the paddle position during runtime get used during runtime, not necessarily the values that you currently see in the Inspector while the game is not running.

Regarding your second question, did you test your idea? If not, do that, please.

See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.