0

I want to attach two shapes together so that their relative position stays always constant.

The shapes must be placed at specific offsets relative to the center of the node.

In Box2D, this can be achieved by making multiple fixtures as mentioned at: How to combine Box2d bodies? , and then using the shape.m_p.Set.

I have managed to do it in 3D by:

  • calling Node::CreateComponent<CollisionCircle2D> multiple times
  • using the CollistionShape::SetPosition method to set the offset

Minimal runnable example: https://github.com/cirosantilli/Urho3D-cheat/blob/76134e9e53e82a95447701f4a67646d47a76d320/compound3d.cpp#L101

However in 2D, I could not find an analogue to SetPosition in the CollisionShape2D class, so all the shapes are co-centric, which I don't want. Minimal example: https://github.com/cirosantilli/Urho3D-cheat/blob/76134e9e53e82a95447701f4a67646d47a76d320/compound.cpp#L35

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985

1 Answers1

0

CollisionCircle2D::SetCenter

For some reason, the analogous method is not on the base class CollisionShape2D, but rather on the derived classes, e.g. CollisionCircle2D::SetCenter.

The CollisionCircle2D::SetCenter method takes a Vector2D parameter that behaves just like CollistionShape::SetPosition.

Working code at: https://github.com/cirosantilli/Urho3D-cheat/blob/4a03873e40ef83b488bb8ca36d6f35c5d046de28/compound.cpp#L44

Yet question self answered while asking :-)

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985