Right I have this simulation which simulates a 2D rollercoaster ride. I have all of the movement running as expected and it looks pretty good (if I don't say do myself ). However I'm at the stage now were I want to add multiple cars to the simulation. I've had a first attempt at it and it doesn't look quite right. What is happening is the front car is moving AWAY from the back car. What I want to do is maintain the distance between the cars between updates so that they do not move away from one another. However I'm not really sure on how to go about this in context of my simulation. Any suggestions on what I should be looking at?.

What I want to do is maintain the distance between the cars between updates so that they do not move away from one another.

You pretty much said it yourself here: Add some kind of force or impulse holding the cars together. You probably already have forces or impulses in action for gravity and for holding the car on the track.

If what I said is too abstract then you should probably give us some details about how you're doing things and we will be able to give you more specific guidelines.

I've done that kind of thing 11 years ago for a PC-Demo called Toasted (there exists a video of the rollercoaster scene if you're interested).

The trick to get the movement right was to stay away from forces but express the physics in terms of energy instead. We calculated the kinetic and potential energy of each car on it's own and used the average energy to calculate the velocity of the car-group at each timestamp. This averaging made sure all cars move at the same pace along the path.

You might be able to do the same with a physics engine if you add hard-joins between the cars. Physically it ought to be the same albeit it's a bit more complex to calculate. 11 years ago nothing like a physics engine existed so we had to improvise something on our own.

Btw - linking multiple cars into the simulation does make a big difference if it feels right or not. It makes the ride much more realistic as we all have been in a rollercoaster and the strange delays that we fell because half of the train is in front or behind you are part of the experience.

Add the centrifugal force to get the camera tilt right, and you have a rollercoaster simulation that will feel right.

The trick to get the movement right was to stay away from forces but express the physics in terms of energy instead. We calculated the kinetic and potential energy of each car on it's own and used the average energy to calculate the velocity of the car-group at each timestamp. This averaging made sure all cars move at the same pace along the path.

Hmmm..this is going to COMPLETELY change the way I have been doing things. It's an interesting idea Nils and I'll investigate more.@z80

If what I said is too abstract then you should probably give us some details about how you're doing things and we will be able to give you more specific guidelines.

I currently have a little mathematical model which approximates the acceleration, I then numerically integrate at each timestep which gives me all the information that I need to place the car at the correct position and make the simulation realistic.

Just a thought here: couldn't I maybe do the same with the acceleration?. Calculate the acceleration at each timestep and average these out and from that get my velocity and positions?. My thinking here is that if the same force is acting on each car, it should in theory have the same velocity and positional change.

Nils, any chance you could provide a link to that animation?. Thanks man.

Just watched it, and I still floors me. That masterpiece run smooth on my 386/40 back then. I get the shiver down my bones just from the music..

Anyways, back to the topic:

Averaging the acceleration could work. You can as well just calculate the forces of all cars and apply the average to each car. If the movement of the cars is constrained to the track this would give you a pretty good simulation. They are linked, so this is even physically correct as you can treat the cars as multiple rigid objects with joins between them.

If anyone is still having this problem I wanted to add my 2 cents: look into "inverse kinematics." It's generally used in the 3d modeling world, but the concepts apply to 2d. It's a system for designating links between objects and the way in which they interact... generally you can just set up the system, plug in numbers for each variable, and watch your objects interact. I used it to put together a 3d skeleton where moving the wrist moved the hand, but not vice versa.

The energy averaging method makes sense. I'm a little confused about applying different forces to the different cars though - aren't they all attached? And if they are, shouldn't they all have the same speed at a give point in time? Like I said above, the averaging method makes sense b/c it treats the cars like a point mass, essentially. And as long as the cars stay on the track, there's no need to think about forces, vectors, etc. It's simply this: the cars all have a given speed (determined by energy : mgh, .5mv\\^2), and the direction of each car is governed by its place on the track. Am I leaving something out?