[Resolved] Hexagonal world

Hi all,

I’m trying to do something that may sound simple, however, I can’t seem to make it work.

This is what I would like to do:

Create a polygon (say: hexagon) area, in which a ball bounces. The lines of the polygons are the boundries. Think of it as the break-out sample, but instead of the full screen being the play field, only the interior of the polygon is.

This is what I tried thus far:

  • create a polygon shape as the ball court. The walls don’t stop the ball though. It’s pushed outside of the polygon shape.
  • use lines to draw the ball court. The ball bounced erratically, because the angled lines turn into rectangles (as shown in hybrid mode)
  • use rectangles to define the polygon. This doesn’t work either: the rectangles are hard to position correctly, as the center is defined as the middle of the object, while trying to rotate. And the rotation causes also erratic behaviour from my bouncing ball.

Any ideas or hints?

Thanks in advance and kind regards.
[import]uid: 146578 topic_id: 25927 reply_id: 325927[/import]

Jon (Beebe) wrote a great blog post on solutions to common physics problems that may be useful for you, it discusses your first point.

For getting the physics shape right you may want to use Physics Editor or look at custom body shapes.

Peach :slight_smile: [import]uid: 52491 topic_id: 25927 reply_id: 105030[/import]

Hi Peach,

Thanks for your reply. I fixed the issue, by revisiting the draw line solution. I forgot to add the shape in the parameters to the physics.addBody method. Beginners mistake, I guess.
Thanks again! [import]uid: 146578 topic_id: 25927 reply_id: 105037[/import]

No worries, am glad to hear that you’ve got it sorted now.

Marking as resolved :slight_smile: [import]uid: 52491 topic_id: 25927 reply_id: 105347[/import]