Skip to main content

MovingSectionCFrameTrack

Combines two tracks such that the shape of one track can be used on another. One is considered the "root" or main. The other, which is optional, is considered the section that defines this shape. The shape is mainly used for the offset positioning of trains.

SectionOffsetTypes

SectionOffsetType determines how to calculate the final "shape" of a group of a positionsOffsets.

By default (SectionOffsetType = 0), the track uses sectionPosition property

Origin and Offset

Origin is a world space position used to calculate a new "origin" or (0, 0, 0) CFrame value.

The origin is determined by the rootTrack and the current position given by the animation player.

Offset is the local space position to this Origin.

The origin is determined by the sectionTrack and the sectionPosition and further adjusted via the sectionOffsetType

SectionPosition = 0 (Default)

Offset is determined by sectionTrack:getCFrame(sectionPosition).

SectionOffset = 1

Uses an additional offset from the "SectionPosition" using the sectionOrigin CFrame property.

sectionOffset = sectionOrigin:Inverse() * sectionTrack:getCFrame(sectionPosition)

In the InstanceData, if SectionOriginRootPosition exists, then this sectionOrigin is calculated from the offset of the "SectionPosition" to rootTrack:getCFrame(sectionOriginRootPosition). This makes it easy to calculate from the existing track. See the example below for more information.

SectionOffsetRotation = 2

Combination of SectionPosition and SectionOffset where the "SectionPosition" is used as the Position and "SectionOrigin" is used as the rotation to form the final Offset.

Example: Getting Shape of "Overlapped" Tracks

This example allows for seamless transitions when switching between two "overlapped" tracks.

Useful for turntables, transfer tracks, elevator lifts, tilt drops, and more.

You will need to set both the SectionPosition and SectionOriginRootPosition values to the position at the overlap of the two tracks.

  • Think of it as this as the intersection of the two curves
  • You will need to adjust this if your CFramedTrain Model uses a different MidPoint
note

For those generating animations, this would be where it transfers from and to.

The SectionTrack would be where it transfers "from". The RootTrack would be where it transfers "to".

It can also be vice versa, just remember that the SectionTrack is the "shape" and the RootTrack is the "movement".

  1. Use SectionOffsetType "SectionOffset" or 1
  2. Set the SectionPosition value to this position at the SectionTrack
  3. Set the SectionOriginRootPosition value to this position at the RootTrack

Types​

SectionOffsetType​

enum
interface SectionOffsetType {
SectionPosition: 0--

Offset origin is determined by sectionPosition when passed to sectionTrack:getCFrame()

SectionOffset: 1--

Offset origin is determined by MovingSectionCFrameTrack.sectionOffset

SectionOffsetRotation: 2--

Offset origin is determined by the CFrame's Position value of sectionPosition and the rotation of MovingSectionCFrameTrack.sectionOffset

}

Properties​

rootTrack​

MovingSectionCFrameTrack.rootTrack: CFrameTrack

The main track used for determining positioning

sectionTrack​

MovingSectionCFrameTrack.sectionTrack: CFrameTrack?

Determines the "shape" of the section used to offset the model's position from the rootTrack. If nil, section will be considered "straight" and offsets will just use the -Z axis of the CFrame returned by rootTrack

sectionOffsetType​

MovingSectionCFrameTrack.sectionOffsetType: number

How it calculates the offsets for the sectionTrack See SectionOffsetType for more info.

sectionPosition​

MovingSectionCFrameTrack.sectionPosition: number

The position on the sectionTrack which will be used when calculating the offset. See SectionOffsetType for more info.

sectionOffset​

MovingSectionCFrameTrack.sectionOffset: CFrame

A CFrame offset value used when calculating the offset. See SectionOffsetType for more info.

Functions​

new​

Constructor
MovingSectionCFrameTrack.new(
rootTrack: CFrameTrack,--

the main track

sectionTrack: CFrameTrack?,--

the "section" track

sectionOffsetType: number?,--

default = SectionOffsetType.SectionPosition

sectionPosition: number?,--

default = 0

sectionOrigin: CFrame?--

default = CFrame.new()

) → MovingSectionCFrameTrack

Default Constructor

fromInstance​

Constructor
MovingSectionCFrameTrack.fromInstance(instance: Instance) → Result<MovingSectionCFrameTrack,string>

Creates from an Instance

Children

{
	RootTrack: CFrameTrackInstance | ObjectValue<CFrameTrackInstance>,
	SectionTrack: CFrameTrackInstance | ObjectValue<CFrameTrackInstance> | nil,
	SectionOffsetType: IntValue?, // if nil, `sectionOffsetType` defaults to `SectionOffsetType.SectionPosition`; see SectionOffsetType for values
	SectionPosition: NumberValue?, // if nil, `sectionPosition` is set to `0`
	SectionOrigin: CFrameInstance?, // if nil, `sectionOrigin` is set to `CFrame.new()`
	SectionOriginRootPosition: NumberValue?, // if nil, `sectionOriginRootPosition` is set to `0`
}

Notes

  • SectionOriginRootPosition gets the sectionOrigin value from rootTrack:getCFrame(sectionOriginRootPosition).
  • If SectionOrigin exists, SectionOriginRootPosition is not used.

getCFrame​

override
MovingSectionCFrameTrack:getCFrame(position: number) → CFrame

Returns a CFrame

getPositionOffsetCFrames​

override
MovingSectionCFrameTrack:getPositionOffsetCFrames(
position: number,
positionOffsets: {number}
) → {CFrame}

Returns a list of CFrames from position offsets

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Default Constructor",
            "params": [
                {
                    "name": "rootTrack",
                    "desc": "the main track",
                    "lua_type": "CFrameTrack"
                },
                {
                    "name": "sectionTrack",
                    "desc": "the \"section\" track",
                    "lua_type": "CFrameTrack?"
                },
                {
                    "name": "sectionOffsetType",
                    "desc": "default = `SectionOffsetType.SectionPosition`",
                    "lua_type": "number?"
                },
                {
                    "name": "sectionPosition",
                    "desc": "default = `0`",
                    "lua_type": "number?"
                },
                {
                    "name": "sectionOrigin",
                    "desc": "default = `CFrame.new()`",
                    "lua_type": "CFrame?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "MovingSectionCFrameTrack"
                }
            ],
            "function_type": "static",
            "tags": [
                "Constructor"
            ],
            "source": {
                "line": 134,
                "path": "src/shared/cframeTrack/MovingSection.lua"
            }
        },
        {
            "name": "fromInstance",
            "desc": "Creates from an Instance\n### Children\n```ts\n{\n\tRootTrack: CFrameTrackInstance | ObjectValue<CFrameTrackInstance>,\n\tSectionTrack: CFrameTrackInstance | ObjectValue<CFrameTrackInstance> | nil,\n\tSectionOffsetType: IntValue?, // if nil, `sectionOffsetType` defaults to `SectionOffsetType.SectionPosition`; see SectionOffsetType for values\n\tSectionPosition: NumberValue?, // if nil, `sectionPosition` is set to `0`\n\tSectionOrigin: CFrameInstance?, // if nil, `sectionOrigin` is set to `CFrame.new()`\n\tSectionOriginRootPosition: NumberValue?, // if nil, `sectionOriginRootPosition` is set to `0`\n}\n```\n### Notes\n- `SectionOriginRootPosition` gets the sectionOrigin value from `rootTrack:getCFrame(sectionOriginRootPosition)`.\n- If SectionOrigin exists, SectionOriginRootPosition is not used.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Result<MovingSectionCFrameTrack, string>"
                }
            ],
            "function_type": "static",
            "tags": [
                "Constructor"
            ],
            "source": {
                "line": 192,
                "path": "src/shared/cframeTrack/MovingSection.lua"
            }
        },
        {
            "name": "getCFrame",
            "desc": "Returns a CFrame",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "CFrame"
                }
            ],
            "function_type": "method",
            "tags": [
                "override"
            ],
            "source": {
                "line": 287,
                "path": "src/shared/cframeTrack/MovingSection.lua"
            }
        },
        {
            "name": "getPositionOffsetCFrames",
            "desc": "Returns a list of CFrames from position offsets",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "positionOffsets",
                    "desc": "",
                    "lua_type": "{number}"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{CFrame}"
                }
            ],
            "function_type": "method",
            "tags": [
                "override"
            ],
            "source": {
                "line": 296,
                "path": "src/shared/cframeTrack/MovingSection.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "rootTrack",
            "desc": "The main track used for determining positioning",
            "lua_type": "CFrameTrack",
            "source": {
                "line": 99,
                "path": "src/shared/cframeTrack/MovingSection.lua"
            }
        },
        {
            "name": "sectionTrack",
            "desc": "Determines the \"shape\" of the section used to offset the model's position from the `rootTrack`.\nIf nil, section will be considered \"straight\" and offsets will just use the -Z axis of the CFrame returned by `rootTrack`",
            "lua_type": "CFrameTrack?",
            "source": {
                "line": 104,
                "path": "src/shared/cframeTrack/MovingSection.lua"
            }
        },
        {
            "name": "sectionOffsetType",
            "desc": "How it calculates the offsets for the sectionTrack\nSee SectionOffsetType for more info.",
            "lua_type": "number",
            "source": {
                "line": 109,
                "path": "src/shared/cframeTrack/MovingSection.lua"
            }
        },
        {
            "name": "sectionPosition",
            "desc": "The position on the `sectionTrack` which will be used when calculating the offset.\nSee SectionOffsetType for more info.",
            "lua_type": "number",
            "source": {
                "line": 114,
                "path": "src/shared/cframeTrack/MovingSection.lua"
            }
        },
        {
            "name": "sectionOffset",
            "desc": "A CFrame offset value used when calculating the offset.\nSee SectionOffsetType for more info.",
            "lua_type": "CFrame",
            "source": {
                "line": 119,
                "path": "src/shared/cframeTrack/MovingSection.lua"
            }
        }
    ],
    "types": [
        {
            "name": "SectionOffsetType",
            "desc": "",
            "fields": [
                {
                    "name": "SectionPosition",
                    "lua_type": "0",
                    "desc": "Offset origin is determined by `sectionPosition` when passed to `sectionTrack:getCFrame()`"
                },
                {
                    "name": "SectionOffset",
                    "lua_type": "1",
                    "desc": "Offset origin is determined by `MovingSectionCFrameTrack.sectionOffset`"
                },
                {
                    "name": "SectionOffsetRotation",
                    "lua_type": "2",
                    "desc": "Offset origin is determined by the CFrame's Position value of sectionPosition and the rotation of  `MovingSectionCFrameTrack.sectionOffset`"
                }
            ],
            "tags": [
                "enum"
            ],
            "source": {
                "line": 18,
                "path": "src/shared/cframeTrack/MovingSection.lua"
            }
        }
    ],
    "name": "MovingSectionCFrameTrack",
    "desc": "Combines two tracks such that the shape of one track can be used on another.\nOne is considered the \"root\" or main.\nThe other, which is optional, is considered the section that defines this shape.\nThe shape is mainly used for the offset positioning of trains.\n\n### SectionOffsetTypes\n\nSectionOffsetType determines how to calculate the final \"shape\" of a group of a positionsOffsets.\n\nBy default (SectionOffsetType = 0), the track uses `sectionPosition` property\n\n:::note Origin and Offset\n\n**Origin** is a world space position used to calculate a new \"origin\" or (0, 0, 0) CFrame value.\n\nThe origin is determined by the `rootTrack` and the current `position` given by the animation player.\n\n**Offset** is the local space position to this **Origin**.\n\nThe origin is determined by the `sectionTrack` and the `sectionPosition` and further adjusted via the `sectionOffsetType`\n\n:::\n\n#### SectionPosition = 0 (Default)\n\nOffset is determined by `sectionTrack:getCFrame(sectionPosition)`.\n\n#### SectionOffset = 1\n\nUses an additional offset from the \"SectionPosition\" using the `sectionOrigin` CFrame property.\n\n`sectionOffset = sectionOrigin:Inverse() * sectionTrack:getCFrame(sectionPosition)`\n\nIn the InstanceData, if `SectionOriginRootPosition` exists, then this `sectionOrigin` is calculated from the offset of the \"SectionPosition\"\nto `rootTrack:getCFrame(sectionOriginRootPosition)`. This makes it easy to calculate from the existing track.\nSee the example below for more information.\n\n#### SectionOffsetRotation = 2\n\nCombination of SectionPosition and SectionOffset where the \"SectionPosition\" is used as the Position and\n\"SectionOrigin\" is used as the rotation to form the final Offset.\n\n### Example: Getting Shape of \"Overlapped\" Tracks\n\nThis example allows for seamless transitions when switching between two \"overlapped\" tracks.\n\nUseful for turntables, transfer tracks, elevator lifts, tilt drops, and more.\n\nYou will need to set both the `SectionPosition` and `SectionOriginRootPosition` values to the position at the overlap of the two tracks.\n- Think of it as this as the intersection of the two curves\n- You will need to adjust this if your `CFramedTrain` Model uses a different `MidPoint`\n\n:::note\n\nFor those generating animations, this would be where it transfers from and to.\n\nThe `SectionTrack` would be where it transfers \"from\".\nThe `RootTrack` would be where it transfers \"to\".\n\nIt can also be vice versa, just remember that the `SectionTrack` is the \"shape\" and the `RootTrack` is the \"movement\".\n\n:::\n\n1. Use `SectionOffsetType` \"SectionOffset\" or `1`\n2. Set the `SectionPosition` value to this position at the `SectionTrack`\n3. Set the `SectionOriginRootPosition` value to this position at the `RootTrack`",
    "source": {
        "line": 95,
        "path": "src/shared/cframeTrack/MovingSection.lua"
    }
}