Changing a Spring Joint's resting length in Unity3d
Asked Answered
P

2

14

According to Spring Joint's documentation, a spring's resting length (the length at which the spring won't try to pull or push together the two bodies it connects) is the distance that was calculated between the two bodies as the joint was created.

However, I'd like to be able to change this resting distance at runtime, and the documentation doesn't mention anything about how the length can be changed.

Is there anyway to accomplish this with Spring Joint? If not, how to create a spring with a set resting length (which can be changed in a script) with Configurable Joint?

Padron answered 7/2, 2017 at 6:10 Comment(2)
I think you need to modify Tollerance property. If you set Spring property to something very high so that spring is nearly stiff you can easily see the effect of Tollerance.Antung
Thanks Nika, I'll check this out. However, this feels like a kind of hacky way to deal with this, is there really no way to explicitly tell Unity what length should a spring be? Cheers!Padron
M
1

The resting length of a spring depends on its spring rate and how much force is applied to it. More force and/or less rate reduces the resting length. You can calculate the compression depth as:

compression = force/rate

Thus, specifying a resting length requires you to know the force the spring will be supporting at rest. Using the above equation you can then calculate the spring rate required for the spring to rest at that length.

I hope this helps.

Machiavellian answered 16/2, 2017 at 12:11 Comment(0)
K
-1

It seems to me that you are looking for the Connected anchor parameter which helps you specify "The point in the connected object’s local space at which the joint is attached." (https://docs.unity3d.com/Manual/class-SpringJoint.html).

The "resting distance" is the distance between the connected anchor and the connected body.

In order to set it to a specific length, you must:

  • Set auto configure connect to false
  • Manually set the connected anchor position based on the length you want
  • *Optional: Activate back auto configure connect (if you want your connected anchor to be updated automatically when the connected body moves)

Hope it solves your problem :)

Kilowatthour answered 21/2, 2021 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.