Newbie, problems with Pong

6 views
Skip to first unread message

Mythics

unread,
Aug 23, 2009, 3:44:49 PM8/23/09
to Physics2D.Net
What's the proper way to handle the equivalent to a pong paddle with
this engine?

Set it's mass to positiveinfinite, and you can't move the thing
either. Any other option I'm aware of, results in either the ball
going through the paddle or the paddle gets knocked off the screen.

Thanks for any and all help,
Mythics

Mythics

unread,
Aug 23, 2009, 3:58:34 PM8/23/09
to Physics2D.Net
I'm also having issues with my 'ball' sometimes bouncing off walls and
other times trying to stick to them..
If I allow the ball to rotate, it works out most of time. The times it
doesn't, it would seem a corner of the 'ball' hits a wall just right
to result in bouncing away at slower/faster speeds than normal.

Any ideas how to cope with this issue?

Bobby5808

unread,
Aug 24, 2009, 6:00:58 AM8/24/09
to Physics2D.Net
Aren't you allowing to ball to rotate? that might cause some bouncing
issues, why are you doing that?.

To move the paddle with a mass of positiveinfinite you have to set the
position manually (ie: body.state.position.linear = new vector2d
(0,0)). I suppose that will work for a pong game, however you won't
have any velocity on the paddle.

You could also use a fixedhingejoint, and then set the anchor-position
of the joint to move the paddle around, and to keep it from rotating
either use a momentofinertia = positiveinfinite or use an anglejoint.

Are you using a circleshape for the ball, or a polygonshape?
Circleshapes are more accurate and might help it bounce more
realistically. Also remember that physics-engines arent as accurate as
real life, and there are always times when things bounce/react funny.
A faster timestep can help with that, if the computers fast enough for
it.

Mythics

unread,
Aug 24, 2009, 7:46:47 AM8/24/09
to Physics2D.Net
If the ball rotates, it looks as if everything is working well more
often.. but then about 1 out of every 5 collisions, something goes
nuts. I was bringing the problem to the surface to be removed by
taking the rotation out of the picture. I'd rather not have some cheap
hack that works only 80% of the time. Having it behave oddly 1 in
every 100 collisions would still be undesirable, but that I could live
with.

There isn't a way to simply disable the engine's body to body
collisions/responses, while still allowing for 'manual' impulses?

I am lacking in knowledge regarding basically all joint types, but I
am currently using momentofinertia = positiveinfinite to stop
rotations.

I am using a circleshape, but there are still some very weird stuff
going on VERY often on even the simplest of situations. I can
understand an engine not accommodating every possible situation, as
they are typically created for very specific ones, but circle to
circle / circle to rectangle collision detection/response doesn't look
THAT difficult to ensure 100% accuracy for. I'm very new to C#, or I'd
at least attempt to do a lot of this on my own (I actually have, but
it's going dreadfully slow).

Thanks for any help,
Mythics

Daniel Story

unread,
Aug 24, 2009, 1:07:33 PM8/24/09
to Physics2D.Net
Your also going to want to have more vertexes per shape than just the
corners. I usually recommend having a center vertex per each flat
plane; you can also do it with VertexHelper.Subdivide (
http://physics2ddotnet.googlegroups.com/web/NeedForSubdivide.png ).
The other thing is the grid spacing, usually you want to set it to be
1/2 or 1/4 minimal width and height of any body.

Mythics

unread,
Aug 24, 2009, 3:07:17 PM8/24/09
to Physics2D.Net
Thank you very much, I did not realize the engine didn't handle the
situation you show in the image. That does, however, make me want to
question something.
Say you have a rectangle 600 pixels high and a 'circle' with a radius
of 5 pixels. Is only subdividing once going to handle that? If so,
will grid spacing need to be even smaller to potentially 'catch' the
'circle'?

I'm still at work, so can't test it out just yet, but I will most
certainly tinker more when I get home. In the mean time, I'm going to
look into the grid spacing bit. I don't honestly know anything at all
about it.

JonoPorter

unread,
Aug 24, 2009, 6:26:54 PM8/24/09
to Physics2D.Net
The Engine when encountering a polygon-circle collision uses the
vertexes of the circle and treats it as a polygon. So if you want more
reliable collisions you can increase the number of vertex use to
create the circle shape. Or you can just use a particle shape.

Mythics

unread,
Aug 24, 2009, 7:32:24 PM8/24/09
to Physics2D.Net
This was actually my problem. I had 1 rectangular 'wall' at each edge
of the screen, trying to get my 'circle' to bounce around inside the
boxed in screen.
With too many vertices, the circle was 'sticking' to the top, left,
and bottom walls while bouncing off the right wall perfectly.

If I do things just right.. sounds silly though.. I can just ensure
that the circle gets a vertex at the far right, top, bottom, and left
sides of the circle. I just don't understand as of yet why it couldn't
handle it properly before.


I'm going to add more vertices to my walls, but even circle to circle
collisions aren't working quite as I'd expect.

Mythics

unread,
Aug 25, 2009, 11:39:30 AM8/25/09
to Physics2D.Net
Please excuse my last post, I was a good ways off on that. It would
seem in reality that the number of vertices my circle has, requires a
time step a good bit lower.
My walls are only 11 pixels wide and the circle has a radius of 5 or 6
pixels. If my circle has 4 vertices, resulting in just a square, I can
use .01 on my timer. If I do 8-12 vertices, I need to have the timer
fire a good deal more often to typically cause a proper collision with
the walls.

I understand it a bit more now, but it is still far from what I was
hoping for with this engine. I was also a bit disappointed to realize
that this engine doesn't handle tunneling itself, but requires the
time step to be lowered or objects to be larger in size/move slower. I
appreciate all the help, but I think I'm going to need to handle the
collision detection/response myself since I'm intending to have a lot
of very small very fast moving objects, with very thin objects for
them to collide into. It'd also be smarter for me to do it myself
since I'm only going to be using very very simple shapes (circles,
squares, rectangles, etc) rather than using a full blown engine.

If anyone here knows of a good library/engine for collision detection/
response that only handles simple 2D objects for C#, I'd love to hear
about it.

Again, thanks for all the help,
Mythics
Reply all
Reply to author
Forward
0 new messages