Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a Spring Joint's resting length in Unity3d

Tags:

unity3d

physx

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?

like image 518
Lucien S. Avatar asked Feb 07 '17 06:02

Lucien S.


1 Answers

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.

like image 121
Rohit Pai Avatar answered Oct 30 '22 07:10

Rohit Pai