Advertisement Jump to content
Sign in to follow this  

spring with natural length !=0 [fixed: programmer stupidity]

This topic is 5130 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My spring model works with 0 natural length, but when natural length is greater than zero, it comes to rest prematurely. image removed to save bandwidth This was captured after the springs came to rest. Both springs have a natural length of two grid units (1 unit=1 meter). The left spring is attached to the cube's center of mass, so only 1 unit worth is visible.
void Spring::tick(double dt)
    vector3 dxv=(b->world_position() - a->world_position()); //direction of force on a by b
    double dx=dxv.length()-N;
    vector3 F = k*dx*Normalized(dxv);

    a->F += F;
    b->F += -F;

where a,b are endpoints (assumably connected to masses), N is natural length, k is spring constant Whats wrong with my source [Edited by - thedustbustr on January 5, 2005 8:08:47 PM]

Share this post

Link to post
Share on other sites
Code looks fine for what you are doing to me.

Some more info would help. What is the computed length at dxv when it comes to rest. It should obviously be the rest length. If it isn't, then there should be a force, track that force and see why it isn't moving the things. Are there other forces applied (Gravity, damping, etc)? Turn those off.

Share this post

Link to post
Share on other sites
[edit] I'm being stupid: since gravity is turned off, the spring won't be pulled down. Stupid me =

There is no force (rather, very little, because I'm not cutting the spring off at a certain threshhold). See the second to last line in the screenshot, the force vector is dumped.

There is no gravity or friction, and if I didn't damp accelerations when I integrate them then it would oscillate forever. I damp every acceleration on every object proportional to the object's velocity.

o->a += -0.3 * o->v; //linear energy loss
o->A += -0.3 * o->w; //rotational energy loss

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!