Ping Pong
Posted: Thu Feb 09, 2012 1:23 pm
Hi there
I'm currently working on a ping pong like game (also to gain a better understanding of BePu) and I have some difficulties to get everything fine. First of all my setup:
- the ball is represented by a dynamic sphere
- there are 6 walls made by static boxes that build one big inverted box (all action happens inside that box)
- two paddles made of 2 static WrappedBodies. They can be moved across the x and the y axis but not across the z axis!
- each player controls one of the paddles and the ball moves between the paddles across the z axis
- gravity is set to zero
Problem 1:
Whenever the ball hits an object it looses linear velocity. Of course this is correct, but after a few touches the ball is at too low speed. I tried to play around with the frictions and the bounciness coefficients which improved the problem but it didn't solve it. If the friction is very low or even zero the ball get's no angular velocity what doesn't look very well. The problem seems to be that the paddles have no movement accross the z axis, so I guess I'll have to simulate this. I.e I could increase the velocity of the ball whenever it touches a paddle, but it is very difficult to find the correct multiplier. So what I would like to know is a) which event should I take to increase the velocity when the ball hits a paddle and b) what other ways are there to keep the ball at a reasonable speed (I don't want to keep the ball at a constant speed, I just want to avoid that the ball becomes too fast or to slow)?
Problem 2:
If the paddles were simple boxes they would have a plane surface(obvious). In this case the ball would always move exactly across the z axis. So I decided to use a bended surface by using a WrappedBody that consists of a box and a sphere so that an incoming ball bounces in a different direction. Is this a wise decision or is there a better approach? Additionaly I would like to controll the velocity of the ball and it's outgoing direction based on the speed of the paddles, how could I implement this(see also problem 4)?
Problem 3:
I've noticed that no matter which coefficients I use I always get the case where the ball hits the wall by an high angle ( maybe 60-70 degree) and instead of having a similar outgoing angle it is so near to 90 degree that the ball isn't moving across the z axis anymore, its only bouncing between two walls. For a high incoming angle this may be correct, but for 60-70 degrees? Is there maybe a problem with the friction or something? This is possible solved with a solution of the first problem, I don't know...
Problem 4:
Is it possible to let the ball make an curve? I would like to have something like this: If a ball comes in from the right for example and hits a paddle that is moving quickly to the right, the ball sould bounce backwards to the left as usual, but additionaly it should make a curve to the left too (in relation with the speed of the paddle). I guess I'll have to do something with the angular momentum, right?
I really hope someone can help me or give me some hints!
Thank you very much!
I'm currently working on a ping pong like game (also to gain a better understanding of BePu) and I have some difficulties to get everything fine. First of all my setup:
- the ball is represented by a dynamic sphere
- there are 6 walls made by static boxes that build one big inverted box (all action happens inside that box)
- two paddles made of 2 static WrappedBodies. They can be moved across the x and the y axis but not across the z axis!
- each player controls one of the paddles and the ball moves between the paddles across the z axis
- gravity is set to zero
Problem 1:
Whenever the ball hits an object it looses linear velocity. Of course this is correct, but after a few touches the ball is at too low speed. I tried to play around with the frictions and the bounciness coefficients which improved the problem but it didn't solve it. If the friction is very low or even zero the ball get's no angular velocity what doesn't look very well. The problem seems to be that the paddles have no movement accross the z axis, so I guess I'll have to simulate this. I.e I could increase the velocity of the ball whenever it touches a paddle, but it is very difficult to find the correct multiplier. So what I would like to know is a) which event should I take to increase the velocity when the ball hits a paddle and b) what other ways are there to keep the ball at a reasonable speed (I don't want to keep the ball at a constant speed, I just want to avoid that the ball becomes too fast or to slow)?
Problem 2:
If the paddles were simple boxes they would have a plane surface(obvious). In this case the ball would always move exactly across the z axis. So I decided to use a bended surface by using a WrappedBody that consists of a box and a sphere so that an incoming ball bounces in a different direction. Is this a wise decision or is there a better approach? Additionaly I would like to controll the velocity of the ball and it's outgoing direction based on the speed of the paddles, how could I implement this(see also problem 4)?
Problem 3:
I've noticed that no matter which coefficients I use I always get the case where the ball hits the wall by an high angle ( maybe 60-70 degree) and instead of having a similar outgoing angle it is so near to 90 degree that the ball isn't moving across the z axis anymore, its only bouncing between two walls. For a high incoming angle this may be correct, but for 60-70 degrees? Is there maybe a problem with the friction or something? This is possible solved with a solution of the first problem, I don't know...
Problem 4:
Is it possible to let the ball make an curve? I would like to have something like this: If a ball comes in from the right for example and hits a paddle that is moving quickly to the right, the ball sould bounce backwards to the left as usual, but additionaly it should make a curve to the left too (in relation with the speed of the paddle). I guess I'll have to do something with the angular momentum, right?
I really hope someone can help me or give me some hints!
Thank you very much!