# Dynamic bridge via joints

When a new object is added to the bridge, the bridge shakes violently, and when objects are added even faster, it breaks.

I've tried changing mass and changing time step, but that doesn't solve the problem.

Code for adding a new object:

[SerializeField]
Rigidbody _last;

[SerializeField]
GameObject _prefab;

void Update()
{
if (Input.GetMouseButtonDown(0))
{
var go = Instantiate(_prefab);
var fj = go.GetComponent<FixedJoint>();
fj.autoConfigureConnectedAnchor = false;
fj.connectedAnchor = new Vector3(0f, 0f, -2f);
fj.connectedBody = _last;
_last = go.GetComponent<Rigidbody>();
}
}


The first cube is kinematic. prefab:

How can you solve this? Thanks for help

• Have you tried positioning the block to be added at the correct position and synching transforms before activating the joint? That way the joint should initialize with zero deflection (or close to it), so it doesn't introduce an oscillation into the chain. – DMGregory Jun 8 at 23:30
• @DMGregory, Yes, it works, but if the bridge moves, then objects attach crookedly, can this be fixed? I have attached the code in the answer. imgur.com/WOilCQF – Aimon Z. Jun 9 at 9:11
• That looks very cool. Try editing your question to explain how this feature is supposed to work in your game, and we may be able to help you find good ways to build it. From your image, I don't think joints will scale to your needs. – DMGregory Jun 9 at 11:01

[SerializeField]
Rigidbody _last;

[SerializeField]
GameObject _prefab;

void Update()
{
if (Input.GetMouseButtonDown(1))
{
var go = Instantiate(_prefab);
var fj = go.GetComponent<FixedJoint>();
go.transform.position = new Vector3(_last.position.x, _last.position.y, _last.position.z + 1f);
fj.connectedBody = _last;
fj.autoConfigureConnectedAnchor = false;
fj.connectedAnchor = new Vector3(0f, 0f, 1f);
_last = go.GetComponent<Rigidbody>();
}
}