Quick Links: Gideros Home | Download Gideros | Developer Guide
Physics for a line
  • Hi, I have multiple lines (using setLineStyle etc) in my game that also need to have objects bounce off them. The line is 5 pixels wide and I have sets of coordinates that they are drawn between so the line can be on any angle. The lines also sometime overlap at the end to form a connection but this only needs to be visual (no physics joints)

    I have looked but I can't find a b2 physics line (with a width). I see there is a PolygonShape but I would either have to calculate coordinates that surround the line or calculate centers and angle for a surrounding box. At this stage I can't work out how to do either of those.

    What is the best way to solve this problem

  • HubertRonaldHubertRonald +1 -1 (+1 / -0 )
    Hi @paul_k_clark Did you see the example Project Physcs 1: Chain on Gideros Studio?
    There's a little code about your question and I believe, it will be able to help you a little

    Likes: antix

  • Hi @HubertRonald, thanks for your reply. That example uses EdgeShape which draws between two points but is only one pixel wide. Since my line is 5 pixels wide it either ends up on one side or in the middle. Either way the other objects enter into the line before bouncing, rather than bouncing off the side.
  • calculating the polygon surrounding the line isn't too complicated.
  • paul_k_clark +1 -1 (+1 / -0 )
    @keszegh, it's been quite a while since I have done this type of math (long long time) so I was looking that would either do it for me or help out. In the end I found a mathlib library that included functions get a shortened point along the line and then rotate it a couple of times to cover the rounded end of the line.

    Likes: keszegh

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with OpenID

In this Discussion

Top Posters