Archived

This topic is now archived and is closed to further replies.

Springs!

This topic is 5890 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

Ok! I''m thinking of creating a car sim, a real physic model of a car! I have done most of the theories in my head, but when it comes to springs, im lost! If you got a car, falling slowly from 1m abow ground, the wheels hit the ground, but it takes maybe five frames, before the car stopps moving downwards, it then jumps a little but up again, now my problem is, how do you transfere the energy from the car falling, to the springs? How do you then get the force that the spring works on the wheels, and on the car??? The problem, is that neither the wheel or the car is static.... but how? Another problem is that you want this to be frame_rate independent, but the key strokes from the player is static for the whole frame... how much of the car sim needs to be frame_rate_independet for real?? i dont talk about movement = car_speed * frame_time sort of frame independent.. please help, i dont need any code, just the theory.... -Anders-Oredsson-Norway-

Share this post


Link to post
Share on other sites

> now my problem is, how do you transfere the energy from the
> car falling, to the springs? How do you then get the force
> that the spring works on the wheels, and on the car??? The
> problem, is that neither the wheel or the car is static....
> but how?

Just simulate the action of the spring. The action is the more compressed it gets the more it pushes, and that''s basically what you want. Conceptually it''s much like a single mass on a single spring, e.g. like a pogo-stick, but there are four springs so you need to do the calculations four times in four places.

You can simulate damping in the springs by adding in a factor based on the spring speed. Varying this and the spring constant (force/extension) gives you wide control over the supspenison behaviour.

Don''t worry about the spring energy: you could calculate but the simulation will work fine without it. Just work out the spring compression, then the force, then apply each force to the car mass. Use these (+ any other forces) to work out linear and angular acceleration then use difference equations to update the velocity and posiiton.

> Another problem is that you want this to be frame_rate
> independent, but the key strokes from the player is static for
> the whole frame... how much of the car sim needs to be
> frame_rate_independet for real?? i dont talk about
> movement = car_speed * frame_time sort of frame independent..

You can use calculations like this but don''t use the frame time: instead use a fixed time step based on the system clock, e.g. 10 ms/100 Hz. The exact step size depends on your simulation, and the suspension is a particularly important part of this. The best way is to use fixed time step which you can vary at will, i.e. assume the time step is constant but don''t assume what it is in your code. This lets you try out different values.

Then run this in a seperate loop from the one that updates the screen and reads the controller(s). This makes the code more complex but in the long run is easier, especially for code that needs to run on a range of platforms/hardware configurations.

Share this post


Link to post
Share on other sites
potential energy for the spring f=1/2 k*x^2
potential energy for the car falling = m*g*h
kinetic energy of the car+springs falling = 1/2*m*v^2 ( m=car mass+ spring masses )
total mecanic conservation
(f+p+k)i=(f+p+k)f ( i=initial , f=final )
i hope it helps or at least it means something form your problem it look to me like a first class phisycs problem, for the frame rate, look around under the word timing
stl sucks
stl sucks
stl sucks

Share this post


Link to post
Share on other sites
This may help.
This is from a calculus book i have...
-
Hooke`s Law:
the force F required to compress or stretch a string(wihtin its elastic limits) is proportional to the distance d that the spring is compressed or stretched from its original length.
That is, F = kd, where k is the "stretchability of the spring"
-
Spelling errors mine. :-D
Basically have length d, you need (force F divided by constant k ) to fully compress the spring.

This might help in your calculations.

I came, I saw, I got programmers block.
~V''''lion

Share this post


Link to post
Share on other sites
Thanks...
Maybe i wasnt clear, but my question was how is this energy transformed? If the time from car falling free, to car standing still is 5 seconds, i know that energy is transferred from the car (mgh) to the springs, and then the spring force becomes stronger than G, and the car moves up again, and so on... i asked how do you handle this is a computer simulation, not to find some values before and after... i know that energy is constant.. And i thank Johnb for his ansver on this... the framerate question was not about framerates, but how much of a physic simulation needs to be framerate_independent? Thanks to Johnb once again...
v71 read my question one more time please :-);

I think i figure it out now..

My answer is a little simplification, where
the spring force back on the car = -k * dist_dif
then all springs have a outer limit where force on car is same as the car bounching from the ground! Now whit the right -k, and the right limit i would get a pretty nice car sim i gues... with a fixed adjustable frame_rate!

Share this post


Link to post
Share on other sites