2D Rollercoaster multiple cars?

956bff9d106b3c4411887b3d32d140c8
0
netwalker 101 Sep 23, 2007 at 19:36

Hi All,

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?.

Ideas/thoughts much appreciated,

netwalker.

9 Replies

Please log in or register to post a reply.

254754b37f468a2926bffcd83bbbf1fa
0
z80 101 Sep 23, 2007 at 20:46

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.

B91eae75cd6245bd8074bd0c3f1cc495
0
Nils_Pipenbrinck 101 Sep 23, 2007 at 21:15

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.

Nils

956bff9d106b3c4411887b3d32d140c8
0
netwalker 101 Sep 24, 2007 at 09:48

Many thanks for your input guys!.@Nils Pipenbrinck

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.

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Sep 24, 2007 at 10:15

@Nils Pipenbrinck

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).

http://www.youtube.com/watch?v=-R4PQhNswDs
Nice, kudo’s :)

46407cc1bdfbd2db4f6e8876d74f990a
0
Kenneth_Gorking 101 Sep 24, 2007 at 14:06

I love how the rollercoaster just slams into the ground at the end :lol:

B91eae75cd6245bd8074bd0c3f1cc495
0
Nils_Pipenbrinck 101 Sep 24, 2007 at 19:37

Cool! My old stuff is on youtube. I wasn’t aware of that.

The demo that really got me into coding is online as well: Second Reality http://www.youtube.com/watch?v=8G_aUxbbqWU&NR=1

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.

25b1b1f6e0449e9d2091abb32b8e9097
0
BraveSirRobin 101 Sep 25, 2007 at 14:27

You can also look at Jakobsen’s Character Physics method which works great for things like that, where hard constraints are needed (Ropes, chains, joints,…). It’s still a penalty method though.

B7109317066ddd5327cb0674388c4974
0
Luz_Reyes 101 Sep 13, 2010 at 20:54

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.

B7109317066ddd5327cb0674388c4974
0
Luz_Reyes 101 Sep 14, 2010 at 19:38

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?