Skip to main content

Record Animation: Getting Track Position

Continuing from the last chapter, we need to adjust the starting position of our animation so that it starts in the Station and not on the brake run.

Let's take a look in our RecorderProgram to see where we can edit this.

Open up the RecorderProgram and scroll to line 76 where is says START_POSITION and END_POSITION.

These values default to 0 which should be just before the brake run on our track.

How do I know? Well, its important to go over what a track position is first.

What is a Track Position?

danger

This section still needs work!

  • Explain the track position
  • Explain the track position of a PointToPoint2 track
  • Explain models (like our train model)
  • Explain how the track position affects trains (MidPoint value)
    • The position is in the middle of the train
  • Track Positions are a small thing, but since they are used by most of the framework, they are deceptively complex (to explain at least).

As mentioned in the track setup section, a track, in terms of the framework, is something that takes a 1-Dimensional position (number) and converts it to a 3-Dimensional position (CFrame). The Track position is that 1-D position.

While this explanation can work well for, say, hinge tracks or time-based tracks, for coasters, especially for coaster physics simulation, it's a different story.

What is the Track Position for our Coaster?

The track position of a coaster track can be thought of a single position along the 3-D line that is our track.

The PointToPoint implementations of tracks, which are the recommended tracks to be used by coasters, create this line using an array of CFrames.

How Do Track Positions Affect Physics?

It's important to know where on our train is the "origin" position as this will affect how and when physics are applied.

A coaster train is not a single point or a single point of contact, but a group of positions along the track. Each of these positions correspond to the wheel sets of our train.

  • What is it in terms our coaster simulation?
    • Train's MidPoint value
    • This means that the relative center of the train is the alpha of our train's length.
    • So, for 0.5, it is the center of our train.
    • This is important as this determines both the position of the train in 3D space along the track, but also how the track affects the physics of the train.
    • You will see more in the Track Sections Data tutorial.

For now, we will get the position for our start position, or where it stops in the station.

Get Track Position

Getting the track position is somewhat difficult as the calculations are internal. Luckily there are plugins to help.

Using the Track Position Plugin

The Track Position Plugin is a free public alternative to the plugin's built-in method, designed to position models along the track.

It uses the same code internally to get track position as the framework's PointToPoint2 track.

Link: Track Position Plugin

First, select the points in the workspace:

After selecting our points, position the cursor where we want our station to be.

If you notice, our position is 179.9999..., but we'll round it up to 180.

Finally, copy the position from the menu.


Once you have your position, copy it and paste it into the RecorderProgram.

note

Note on MidPoint adjustment (assuming MidPoint is 0.5)

If you want to make it so that the position is at the front of the train, you can subtract by half the total length of the train:

local trainLength = mainCFrameTrain.length
local halfTrainLength = trainLength / 2

local position = 100
local positionFront = 100 - halfTrainLength

As of Plugin v2.0.0-alpha.9, this line has already been added to the RecorderProgram template.

We have now adjusted our starting position. However, if you were to run it (again), you would notice that it will valley at the bottom of the lift as though the lift wasn't even working. In the next tutorial, we will will setup the lift and other track sections to make our coaster move through the layout.