Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ructions

Objects Not Moving Together

This topic is 5331 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am making am arkanoid game and at the start i want my ball and paddle to move together across the screen together. so i set the x coordinates to equal eachother. ball.x = paddle.x; here is the code that draws them glLoadIdentity(); glTranslatef(0.0f,-6.5f,-20.0f); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(PaddleWidth + paddle.x , 0.0f + paddle.y, 2.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.0f + paddle.x , 0.0f + paddle.y, 2.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.0f + paddle.x , PaddleHeight + paddle.y, 2.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(PaddleWidth + paddle.x ,PaddleHeight + paddle.y,2.0f); glEnd(); // Done Drawing The paddle glBindTexture(GL_TEXTURE_2D, texture[1]); glTranslatef(0.0,-6.5f,-20.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(0.7f + ball.x , 0.7f + ball.y , 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f + ball.x , 0.7f + ball.y, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f + ball.x , -0.7f + ball.y, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(0.7f + ball.x , -0.7f + ball.y, 0.0f); glEnd(); // Done Drawing The ball but them i move them across the screen the ball never stays in the same place as the paddle it stays behind it. i have printed the x ordinates to the screen and they are the same so i dont know thats wrong with it.. any help. newbie to opengl.

Share this post


Link to post
Share on other sites
Advertisement
Remove the 2nd call to glTranslatef, it makes everything move another (0.0,-6.5f,-20.0f) units so the ball will always be (0.0,-6.5f,-20.0f) units away from the paddle.

[edited by - Tree Penguin on January 16, 2004 6:04:19 PM]

Share this post


Link to post
Share on other sites
thanks thats working better now.

another question i am testing for collsion of the ball off the paddle and am using this code.

if ((ball.x<=paddle.x+PaddleWidth)&&(ball.x>=paddle.xPaddleWidth)&&
(ball.y<=paddle.y+PaddleHeight)&&(ball.y>=paddle.y-PaddleHeight))

i am then reflecting the ball using

// reflect ball
ball.dy=-ball.dy;

// push ball out of paddle since it made contact
ball.y+=ball.dy;

but it does collsion even when its not hitting the paddle any suggestions

Share this post


Link to post
Share on other sites
You haven''t told the program to revert the x speed, so the ball probably bounce like the paddle was perpendicular to the one actually there, so add the line:
ball.dx=-ball.dx;

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!