Pong: Can't get much simpler than this.

Aug 23, 2009 at 2:26 PM

I'm just trying to create my own little demo app using Farseer. The first project I started bombed out (see my previous thread for details) due to my laziness in not wanting to work around the limitations of this engine.

So, here I am trying one of the simplest concepts I could think of. The problem and reason I'm posting, is because I'm not quite sure how to get a rectangular body/geom to behave as if static for collision purposes but non-static so that manual (non-engine handled) forces can be applied.

Is this something that is currently doable in the engine and I'm missing it, something that may be added in the future, or will I need a work-around to even accomplish a pong project? =\

 

Thanks again for any and all help,

Mythics

Aug 23, 2009 at 2:33 PM

I would create a static object(paddle), and another object that is controlled by the keyboard the obbject controlled by the keyboard could be renered invisible or off screen and you could update the coordinates of the static object based on the position of the object.  

Or you could just set the paddle up so that the code keeps it from changing angles or positions  other than up/down.

Aug 23, 2009 at 3:41 PM

Are you trying to make pong to learn farseer?

Or are you just trying to make pong? Because if you are it would be much easier to just do the collsions yourself rather than an entire physics system just for a pong type game.

 

An object can be static and still moved. Or you can just make it non static and set the object so it can only go up and down and not left and right. Or you could just make it really really heavy compared to the ball but there is no need to.

Aug 23, 2009 at 4:45 PM

Thank you both for the replies.

To answer you danthekilla, I was trying to make pong simply to start learning Farseer. The first project I started was apparently a bad idea, since a 'ball' can not roll smoothly over multiple 'blocks' that are next to one another without a hack/workaround.

"An object can be static and still moved."

Without manually setting it's position?

 

"Or you can just make it non static and set the object so it can only go up and down and not left and right."

Well, yeah.. but how do you do that exactly? If it's not static, the ball knocks the paddle off the screen (quite amusing to see, but not the desired effect). If you try to cheat in a simplistic way, like every update setting the paddle's x position back to where it should be, the ball still collides into the paddle as it would on any other non-static body.

 

"Or you could just make it really really heavy compared to the ball but there is no need to."

While this could work.. it's most certainly not what I think should need to be done. I really just expected the engine to handle 'IsStatic' within it's own mechanisms during collisions, and not to affect coded applying of impulses.

 

 

To d1ag0n, your first suggestion would probably work absolutely fine.. however, the vertical force of a moving paddle would not then be applied to the ball.. correct?

"Or you could just set the paddle up so that the code keeps it from changing angles or positions  other than up/down."

Similar to my response to danthekilla, I don't really know how I should go about doing that without having to modify the engine.

 

 

To toss another question into this, how can I lock an object's rotation? I'd like to simply turn off a specific body's rotation altogether, like the paddle in this case (but I'd prefer to do it for the ball as well to avoid oddities due to not using an actual circle). I tried setting the moment of inertia to float.positiveinfinity, but that can quickly result in a NaN error on the angular velocity.

Aug 24, 2009 at 10:53 PM
Edited Aug 24, 2009 at 11:01 PM
Mythics wrote:

To toss another question into this, how can I lock an object's rotation? I'd like to simply turn off a specific body's rotation altogether, like the paddle in this case (but I'd prefer to do it for the ball as well to avoid oddities due to not using an actual circle). I tried setting the moment of inertia to float.positiveinfinity, but that can quickly result in a NaN error on the angular velocity.

just set the rotation to zero every frame.

 

Aug 25, 2009 at 7:49 AM

What if you make a field where there are geometries on the edges and in the center but they only collide with the paddles, making a sort of "track" for your paddles?

Aug 25, 2009 at 2:14 PM

SlimeQ, would I not risk the engine's update method setting the rotation to something other than 0, handling collision info, etc before I got to reset the rotation to 0? I'm at work atm, but will try it when I get home.

 

RogueCommanderIX, sorry.. it might just be my being a bit tired, but I'm not sure I quite following your question. Would I be putting rectangular bodies all the way around the paddle (two of them stretching as far as the paddle can move), for the paddle to collide with, but those bodies not collide with the ball while the paddle would collide with both the outter bodies AND the ball?

Aug 27, 2009 at 10:45 AM

That's just about it!