Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to get collision coordinates onPostSolve(event) ? — Gideros Forum

How to get collision coordinates onPostSolve(event) ?

RogerTRogerT Member
edited December 2012 in General questions
Hi guys,
I was wondering if there's a way to get collision coordinates ( not center of either colliding bodies, but the place of actual impact ) from a onPostSolve(event) ?
I tried event.x and event.y , but they return a nil value.

Thanks.

Likes: DungDajHjep

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • atilimatilim Maintainer
    edited December 2012 Accepted Answer
    @RogerT - it's (getting contact info) not implemented yet.

    Likes: RogerT

    +1 -1 (+1 / -0 )Share on Facebook
  • Hi,

    I was wondering if this has been implemented or if an alternative to get collision coordinates exists?
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • ar2rsawseenar2rsawseen Maintainer
    edited March 2013
    @Mells, yes that have been implemented.
    Going from the top of my head, but I think that every collision event has a contact property, which is a b2.Contact instance as in:
    --define begin collision event handler function
    function scene:onBeginContact(e)
        --b2.Contact object from the docs
        print(e.contact)
    end
    You can then use contact object to retrieve manifolds (contact points) or even reset collision friction and restitution.

    Likes: DungDajHjep

    +1 -1 (+1 / -0 )Share on Facebook
  • MellsMells Guru
    edited March 2013

    You can then use contact object to retrieve manifolds (contact points) or even reset collision friction and restitution.
    @ar2rsawseen
    Thank you
    This is what I have so far (I had to dig to find relevant informations) :
            local manifold = event.contact:getManifold()
    	for i, j in pairs(manifold.points) do
    		for a, b in pairs(j) do
    			print (a, b)
                            -- normalImpulse	number
                            -- localPoint	table
                            -- tangentImpulse	 number
                            for c, d in pairs(j.localPoint) do
    			         print (c, d)
                                     -- y
                                     -- x
    		end
    	end
    I am not sure that those x, y are the ones I was looking for?
    I wanted to get the coordinates of the collision, but I got some coordinates that are local to...? I have no idea.

    Is iterating through the table the more direct way to get those datas?
    I feel that I'm missing a simple way but can't find anything relevant in the API.

    Edit : I really can't see how I can find the collision's global coordinates.

    Likes: DungDajHjep

    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
    +1 -1 (+1 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    edited March 2013
    @Mells for global coordinates you should use :getWorldManifold() and the points provided should be global to box2d world :)
    I don't remember the exact structure now, but you can always print it out to see the structure of the table:
    --recursive print of tables
    function print_r (t, indent, done)
      done = done or {}
      indent = indent or ''
      local nextIndent -- Storage for next indentation value
      for key, value in pairs (t) do
        if type (value) == "table" and not done [value] then
          nextIndent = nextIndent or
              (indent .. string.rep(' ',string.len(tostring (key))+2))
              -- Shortcut conditional allocation
          done [value] = true
          print (indent .. "[" .. tostring (key) .. "] => Table {");
          print  (nextIndent .. "{");
          print_r (value, nextIndent .. string.rep(' ',2), done)
          print  (nextIndent .. "}");
        else
          print  (indent .. "[" .. tostring (key) .. "] => " .. tostring (value).."")
        end
      end
    end
     
    --use it on table
    print_r(t)

    Likes: DungDajHjep

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.