Ping Pong

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Phippu
Posts: 24
Joined: Fri Jun 03, 2011 3:39 pm

Ping Pong

Post by Phippu »

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!
Fe_Yoshi
Posts: 397
Joined: Tue Jul 04, 2006 5:05 pm
Location: New Tower!

Re: Ping Pong

Post by Fe_Yoshi »

That's a whole lotta text for Ping Pong!

Here's how to do it simply:
| /\ |
| / \ |
| / \ |
| / * |
| / | 8)
:o |/ |
OOOOOOOOOOOOF forum does not like whole lotta spaces!!!!
. . |. . . . . /\ . . . . |
. . | . . . ./ . .\ . . . |
. . | . . ./ . . . .\ . . |
. . | . ./ . . . . . * . .|
. . | ./ . . . . . . . . .| 8)
:o |/ . . . . . . . . . .|
There we go. Hope that helps!
It's simple, just take the hydraulic phase ship emulator and attach it to the photon particle emitter, BAM, new tower!
Phippu
Posts: 24
Joined: Fri Jun 03, 2011 3:39 pm

Re: Ping Pong

Post by Phippu »

Hm, yeah thanks, that's what I already have :D At least for the curved ball movement I have found the "magnus effect", maybe that is a partial solution...
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Ping Pong

Post by Norbo »

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)?
There isn't a single 'correct' multiplier, so I would not recommend going that route. Here's a few things to look at:
-The default blending mode for friction and bounciness is to use the average. If the paddle and ball don't both have a bounciness of 1, for example, then the combined bounciness will be less than 1 using the default mode.
-Make sure the CollisionResponseSettings.BouncinessVelocityThreshold isn't getting in the way. If a collision occurs with low velocity, it won't bounce at all. For pong, you can just set this threshold to 0.
-Finally, set the ball's LinearDamping and AngularDamping to 0 if they aren't already. Damping removes energy over time.
-If there are any motion clamping mechanisms being used, ensure that they are not sapping energy incorrectly.
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?
I'm not sure how the wrapped body is set up. A wrapped body could work fine so long as it's configured well. Do note that a box paddle would not always result in the same normal- a ball colliding on the edge of a box can have any intermediate normal.
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)?
As long as the paddles are being controlled with velocities as opposed to directly setting the Position, the speed of the paddle will influence the linear and angular velocity of the ball physically. If the paddle is moved by setting the position of the paddle directly, it amounts to teleportation. Teleporting objects do not have velocities that match their movement, so collision response will not behave correctly.
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...
This sounds like angular velocity. If a paddle introduces a large angular velocity to a ball, the next impact with a wall will produce a significantly different direction. If friction was zero on every object, this would not happen (although then it would be technically less 'realistic').

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?
...
At least for the curved ball movement I have found the "magnus effect", maybe that is a partial solution...
The magnus effect is indeed what you want: viewtopic.php?f=4&t=1454
Post Reply