# 2D Rollercoaster multiple cars?

9 replies to this topic

### #1netwalker

Member

• Members
• 72 posts

Posted 23 September 2007 - 07:36 PM

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.

### #2z80

Valued Member

• Members
• 104 posts

Posted 23 September 2007 - 08:46 PM

Quote

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.

### #3Nils Pipenbrinck

Senior Member

• Members
• 597 posts

Posted 23 September 2007 - 09:15 PM

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
My music: http://myspace.com/planetarchh <-- my music

My stuff: torus.untergrund.net <-- some diy electronic stuff and more.

### #4netwalker

Member

• Members
• 72 posts

Posted 24 September 2007 - 09:48 AM

Many thanks for your input guys!.

Nils Pipenbrinck said:

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 said:

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.

### #5.oisyn

DevMaster Staff

• Moderators
• 1842 posts

Posted 24 September 2007 - 10:15 AM

Nils Pipenbrinck said:

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

Nice, kudo's
-
Currently working on: the 3D engine for Tomb Raider.

### #6Kenneth Gorking

Senior Member

• Members
• 939 posts

Posted 24 September 2007 - 02:06 PM

I love how the rollercoaster just slams into the ground at the end :lol:
"Stupid bug! You go squish now!!" - Homer Simpson

### #7Nils Pipenbrinck

Senior Member

• Members
• 597 posts

Posted 24 September 2007 - 07:37 PM

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

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.
My music: http://myspace.com/planetarchh <-- my music

My stuff: torus.untergrund.net <-- some diy electronic stuff and more.

### #8BraveSirRobin

New Member

• Members
• 1 posts

Posted 25 September 2007 - 02:27 PM

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.

### #9Luz Reyes

Valued Member

• Members
• 112 posts

Posted 13 September 2010 - 08:54 PM

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.

### #10Luz Reyes

Valued Member

• Members
• 112 posts

Posted 14 September 2010 - 07:38 PM

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?

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users