Sticky power up?

Started by
10 comments, last by FirstStep 7 years, 9 months ago

Indeed it does, the origin of the ball is at the paddle, so you need to add the paddle coordinate to the ball coordinate to get the absolute pixel coordinate.

I would think that keeping the ball relative to the paddle when it's freely moving would be messy (you'd have to update the ball coordinates both for ball movement and for paddle movement). Thus you may want to switch between "ball in pixel coordinates" and "ball relative to paddle" when making the ball stuck (and switch back to pixel coordinates when it gets unstuck.

You can use the above equations to convert the ball.position vector, like


// Unstuck ball -> Stuck ball
ball.position.x -= paddle.position.x;
ball.position.y -= paddle.position.y;
// Since you add paddle.position again when drawing it, the ball gets drawn at the exact same place (until you move the paddle  )

// Stuck ball -> Unstuck ball
ball.position.x += paddle.position.x;
ball.position.y += paddle.position.y;
// Rendering the ball now happens without adding the paddle position, so you have to change the ball coordinates to compensate.
Advertisement

HA!

I got it. And I think youre right.

I took the offset of the ball and position once only..


   offset = position.X - paddle.position.X;

and then on the update method


 float x = paddle.position.X + offset;
 position = new Vector2(x, position.Y);

WORKS! Thanks

This topic is closed to new replies.

Advertisement