omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Crude HitTest

    Pythonista
    5
    11
    6641
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • eliskan175
      eliskan175 last edited by

      http://gist.github.com/cbc554a5aab2350b847d

      Experimenting with hitTest function. It's a bit rough, I am still learning, but I thought it could be helpful. The idea is you have two objects with "bounding boxes" and this function tells which direction the object is being struck. Used in this example to push one box with the other.

      ATM it only works on box-shaped bounding boxes but that would be easy to change. Let me know what you guys think and how to improve!

      It also has a couple side features like the size of the boxes changes dynamically according to the gravity.z .. Just ignore those haha the really interesting part for game design is the hit test.

      1 Reply Last reply Reply Quote 0
      • eliskan175
        eliskan175 last edited by

        https://gist.github.com/5eb6c63a8e4ab9998e0d

        This is a circle-to-circle based hittest. Used a little nifty math to make it accurate.

        1 Reply Last reply Reply Quote 0
        • Matthew_Murdoch187
          Matthew_Murdoch187 last edited by

          This works really nicely - thanks!

          1 Reply Last reply Reply Quote 0
          • eliskan175
            eliskan175 last edited by

            Thank you! Another example I have been playing with. In this one I modified the particles example because I wanted to test hitting a large array of objects. At about fifty it results in lag, probably because my coding is subpar..

            https://gist.github.com/68959f100b41187fa3d6

            Any advice or improvements is always welcome!

            1 Reply Last reply Reply Quote 0
            • eliskan175
              eliskan175 last edited by

              Very nice work!

              I was thinking about a quad implementation but I didn't know exactly how to do something like that. You demonstrated that wonderfully and pretty much tripled the amount of particles the scene can handle. Good job :)

              I'm also quite impressed with how you made the already truncated circle hittest even shorter!

              Thank you for the contribution, that's pretty cool stuff and I will definitely learn from this.

              1 Reply Last reply Reply Quote 0
              • yodayoda230
                yodayoda230 last edited by

                .

                1 Reply Last reply Reply Quote 0
                • yodayoda230
                  yodayoda230 last edited by

                  thanks dlivingstone! - very devious ways of speeding up the collision checks! :)

                  1 Reply Last reply Reply Quote 0
                  • sea56
                    sea56 last edited by

                    Very cool.

                    1 Reply Last reply Reply Quote 0
                    • yodayoda230
                      yodayoda230 last edited by

                      I see that, although you limit the number of checks cleverly, you still have to check the distance for some, and you use "if((dxdx)+(dydy)<radii*radii)"

                      I notice there is a command in the documentation-

                      Point.distance(other_point)
                      #Return the cartesian distance to a different Point object.

                      And wondered if you could incorporate that instead? Or if you had tried and found it slower than your method

                      1 Reply Last reply Reply Quote 0
                      • Sebastian
                        Sebastian last edited by

                        I've noticed that too, I even use it in my own codes, but it does use the square root function which I believe can make it a bit slower.

                        1 Reply Last reply Reply Quote 0
                        • yodayoda230
                          yodayoda230 last edited by

                          Thanks S

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Powered by NodeBB Forums | Contributors