Object with joints flies away at high velocity on collision

I am currently making a game where the player constructs vehicles out of blocks. I am achieving this through having rigidbodies for each ‘group of blocks’ separated by ‘function blocks’ (e.g. motors, that can rotate) to allow for movement of the rigidbodies/groups of blocks. These function blocks connect the rigidbodies by HingeJoints.

I added gravity as the game will be set in space. I update the velocity of the vehicle in a method called on a fixed timeStep of 0.01, using AddForce.

private void UpdateVelocity()
{
    rb.AddForce(velocity - lastVelocity, ForceMode.VelocityChange)
}

The problem is, now whenever I collide with something, the vehicle freaks out and flies away at ridiculously high velocities. I’ve tried many different approaches but I can’t figure out the solution. I don’t think it’s related to me using VelocityChange as it doesn’t work with other ForceModes either.

I am relatively new to using joints so any help would be appreciated!

Before collision:


After collision:

Gif:
ezgif.com-video-to-gif.gif
(In the gif the vehicle is two blocks separated by a motor in the middle, using HingeJoints to connect them)

Bump

So your code adds an acceleration, calculated as the difference between a new “velocity” and what I assume is the object’s velocity during the previous physics step. How do you calculate both “velocity” and “lastVelocity” here?