Jump to content

Getting world position of vertices on P2 Physics body


dwhiffing
 Share

Recommended Posts

Hey guys,

I'm making a top down survival horror game and I've made a cave maze out of p2 physics bodies and i am in the process of implementing raycasting.

I'm having trouble getting the position of the vertices of the p2 physics bodies. 

I understand that p2 uses different units than phaser, and I read somewhere that the conversion is pretty much just * -20

Currently, I'm doing something like this:

 

sprite.body.data.shapes.forEach(shape => {
        shape.vertices.forEach(vert => {
          let out = []
          this.sprite.body.toWorldFrame(out, vert)
          this.points.push(out[0] * -20, out[1] * -20)
        })
      })

 

which should give me a big list of all of the points for the cave. Its getting me very close, but I think I'm missing something small which is throwing every thing off.

 

Can anyone point me in the right direction?

Thanks!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...