# Box2d How to connect distance joint to the ground?

I have a rectangular fixed size world. I want to connect a body inside it to any place(near that body) in the world with a b2DistanceJoint. Do I need to create a large static body with the size of the world that can't collide with anything? Or is there a better method? Will it slow down simulation speed if I have around 300 bodies moving on the surface of this static body?

Do I need to create a large static body with the size of the world that can't collide with anything?

No.

Or is there a better method?

In the wise words of master Yoda:

Size matters not

In this case it means that the joint anchor points on a body need not be inside any of the fixtures of the body. They can be miles away if you want.

Make a small b2body somewhere well outside the gameplay area, make it a b2_staticBody, and make the fixture a sensor body so that any collisions that do happen to occur don't affect the simulation. Then use this body whenever you want to join something to the ground.

Will it slow down simulation speed if I have around 300 bodies moving on the surface of this static body?

Yes. The reason you want to make a small body is precisely because of what you mentioned. Any collisions with this body are meaningless, and box2d creates a contact object and stores it on the world for every contact between fixtures. It also iterates through this list every time the step function is called. So by keeping it small and out of the way you can conserve memory and cpu time.

• Thanks! That's exactly what I wanted! And I have a static world border, so I don't even need an additional body, I guess. – a_vasilkov Feb 1 '16 at 22:30
• Cool. Glad I could help. :) – NauticalMile Feb 1 '16 at 23:35