1

I would like to make a custom physicsjs body type called "player" which is a composition of 2 circles and one square. The figure would look like a square with a circle attached to the left and right sides of the square. I was thinking of just making a custom polygon into this shape, however the circles will not be true circles, but instead look more like a hexagon. Any ideas how to make physicsjs draw a curved line between verticies instead of a straight line or how to combine existing bodies into one new body?

Cœur
  • 37,241
  • 25
  • 195
  • 267
lufthansa747
  • 1,923
  • 3
  • 26
  • 39

1 Answers1

1

composite bodies still need to be built in. There's no easy way to do this, but you can create a custom body that creates other bodies (eg, custom body that extends a square, that creates two circles). Just add a "connect" and "disconnect" method to the custom body so you can add and remove the extra circle bodies when it's added to a world.

Then you can use verlet constraints to attach them together.

As for the appearance, you'd need to find a way to draw that yourself with canvas. If you wanted to have the physics of a curved polygon, you'd have to write that yourself. So it's probably easier to just skin it with an image. To do that just set "body.view = myImage"

This is a bit outdated, but has some examples: http://flippinawesome.org/2013/12/02/building-a-2d-browser-game-with-physicsjs/

Jasper
  • 1,193
  • 1
  • 9
  • 14
  • Could the custom body manage adding the verlet constraints to the world. thus in order to add the body i would do world.add(body) instead of having to do world.add(body), world.add(bodyconstraint)? – lufthansa747 May 15 '14 at 17:43
  • yes. add the methods "connect" and "disconnect" to the custom body. They will be run when the body has been added/removed from the world. Then inside those methods, handle adding/removing the constraints – Jasper May 16 '14 at 19:40