1
\$\begingroup\$

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.

enter image description here

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:

enter image description here

How can you solve this? Thanks for help

\$\endgroup\$
3
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – DMGregory Jun 8 at 23:30
  • \$\begingroup\$ @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 \$\endgroup\$ – Aimon Z. Jun 9 at 9:11
  • \$\begingroup\$ 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. \$\endgroup\$ – DMGregory Jun 9 at 11:01
0
\$\begingroup\$
[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>();
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.