# Help Plz

## Recommended Posts

Hi, I am Implementing a game my ball is moving upward and hitting the top wall,left wall wat the program meant to do ? but there is a bat in the middle of display window,When the ball have to hit the bat it have to bounce back towards the wall.I displayed the bat with the three points x,y,z and my look like a straight line like e.g. --------------- x y z If the ball hit the bat after hitting it how will it bounce back? i m using equation if ((v <= x) || (v <= y) || (v<=z)) { d = -d; } where v is movement of ball in x direction, x,y,z are the position of bat.

##### Share on other sites
[repost] That post was not easy to understand ... can you say it again using different words?

You need a ball position and a ball velocity. "V" isn't enough by itself.

Also, what shape is your bat? Either x,y,z are scalars, in which case they specify a point in space, or they are vectors, in which case you have a 3 dimensional triangular bat?

##### Share on other sites
Ball is drawn with the
glvertex2f(ab,ba);
where as ab is 0.6 and ba is 0.6
No basically my ball is in space but when it will hit the bat it have to rebounce, the bat is in shape of line its not 3-dimensional its 2-dimensional.To draw the bat i need three point which i used x,y,z and the bat look like ______ .x is the starting point of bat,z is middle point of bat and z is end point of bat its is the wayy of drawing in opengl.i can move the bat use the key button e.g A and B. if i press A the bat moves towards left and if i press B bat move towards right.With the help of these button i have to touch ball on the bat.My english is not good i hope you understand it wat i m trying to say.

##### Share on other sites
OK, I understand. I don't understand why you have 3 points on the bat - you just need 2, and since you called two of them 'Z' I shall make my own up. I still don't understand the ball :)
//my ball is at (ball.pos.x,ball.pos.y)//my ball is travelling with (ball.velocity.x, ball.velocity.y)//my bat is at (bat.left, bat.right, bat.y)//my ball hit the bat if it is travelling downwards through the//position of the bat:if(ball.velocity.y < 0 && ball.pos.y < bat.y){  if(ball.pos.x < bat.left || ball.pos.x > bat.right)  {    //it is outside the bat area, it is lost:    cout << "oops, the ball has fallen off the screen"  }  else  {    //it is within the bat area, bounce:    cout "BOING"    ball.velocity.y = - ball.velocity.y;  }}

Maybe this forum needs a "hello physics" tutorial?

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628366
• Total Posts
2982274

• 10
• 9
• 13
• 24
• 11