Ping pong problem
Ive started to do a simple 3d ping pong game..
The ball bounces perfectly round the court,
Both bats move perfectly,
When the x,z position of the bat is = to the x,z position of the ball i want the ball to bounce in the opposite direction.
The problem...
If x postion of the bat matches x position of the ball....the ball jumps to the z position of the bat even if the z position of the bat and ball are not equal.
int BallHit()
{
if ((xball>=xpos-2.0f) && (xball<=xpos+2.0f) && (zball=zpos))
{
zdirection=(zballspeed);
}
return TRUE;
}
You need to change the = in == in your if thing.
x =2 then x becomes to
and with if x==2 than you ask if X is equal to 2
x =2 then x becomes to
and with if x==2 than you ask if X is equal to 2
Thanks for the reply...
I tried the way you said...it cured the ball jumping back to the player z position but it still didnt detect when it hit the bat...
I found it works this way...seems accurate while playing but the code looks messy.
int BallHit(GLvoid)
{
if ((xball>=(xplayerA-2.0f)) && (xball<=(xplayerA+2.0f)) &&
(zball<(zplayerA+2.0f)) && (zball>(zplayerA+1.0f)))
{
zdirection=(zballspeed);
}
if ((xball>=(xplayerB-2.0f)) && (xball<=(xplayerB+2.0f)) &&
(zball>(zplayerB-2.0f)) && (zball<(zplayerB-1.0f)))
{
zdirection=-(zballspeed);
}
return TRUE;
}
Edited by - Lee J K on March 2, 2002 6:34:51 AM
I tried the way you said...it cured the ball jumping back to the player z position but it still didnt detect when it hit the bat...
I found it works this way...seems accurate while playing but the code looks messy.
int BallHit(GLvoid)
{
if ((xball>=(xplayerA-2.0f)) && (xball<=(xplayerA+2.0f)) &&
(zball<(zplayerA+2.0f)) && (zball>(zplayerA+1.0f)))
{
zdirection=(zballspeed);
}
if ((xball>=(xplayerB-2.0f)) && (xball<=(xplayerB+2.0f)) &&
(zball>(zplayerB-2.0f)) && (zball<(zplayerB-1.0f)))
{
zdirection=-(zballspeed);
}
return TRUE;
}
Edited by - Lee J K on March 2, 2002 6:34:51 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement