Repository navigation
Orientation
Which way the carriage holding the axle is pointing, read from the physics body.
These are the real angles on the rail. Do not confuse them with Body offset, which
is the decorative angle you set yourself. getYaw() is the direction the train is driving,
getBodyYaw() is the extra turn you asked the body to hold on top of it.
All of them throw sub level not available when the body is not loaded, which happens when the
train is outside a loaded chunk. Wrap them in pcall in a program that runs while nobody is near.
All three measure from the locomotive's front, the way the Bearing Axle faces, so tilting the
train on one axis does not change the other two. They come back rounded to hundredths of a degree.
They read the train on the track, setBodyRoll, setBodyPitch and setBodyYaw never change them.
Direction in degrees. 0 is south, the same as vanilla Minecraft, and it counts up clockwise.
It wraps around. 359 goes back to 0, so subtracting two readings gives a large wrong jump once per turn. To fix that, add 540, take the remainder after dividing by 360, then subtract 180:
local turn = (yaw - lastYaw + 540) % 360 - 180That gives the shortest turn between the two readings, with a sign, and it never jumps.
Nose up or down in degrees. Positive means pointing down, the same as vanilla Minecraft, so a climbing train reads negative.
Side tilt in degrees.
print(string.format("yaw %.1f pitch %.1f roll %.1f",
train.getYaw(), train.getPitch(), train.getRoll()))yaw 180.0 pitch 0.0 roll 3.0
True when the carriage is still upright. minDot is how strict you want to be, from 0 to 1.
Use 0.9 for level, 0.7 for still rideable. 1.0 means perfectly flat, and almost nothing passes that.
The number is the dot product of the carriage's up direction with world up. It is 1 when the two point the same way and 0 when the car is on its side.
if not train.isUpright(0.8) then
print(string.format("leaning: roll %.1f pitch %.1f", train.getRoll(), train.getPitch()))
endleaning: roll 12.4 pitch 1.1
The carriage body's speed through the world as a table {x, y, z}.
This one is blocks per second, not per tick. It comes straight from the physics body, so it is
the one exception to the rule in Conventions. Divide by 20 to compare it with
getSpeed().
It is not the same as getSpeed(). getSpeed() is one signed number along the rail. This is the
real movement through the world, so it includes sideways and up or down movement that the rail speed
hides. That makes it useful on a derailed train.
local v = train.getVelocity()
print(string.format("%.2f b/s horizontal", math.sqrt(v.x ^ 2 + v.z ^ 2)))
print(string.format("%.2f b/s vertical", v.y))15.83 b/s horizontal
-0.40 b/s vertical
A falling car reads a large negative v.y while getSpeed() still reports whatever it was doing
along the rail.
Start here
Reading the train
- Identity
- Motion
- State
- Station
- Signals
- Track ahead
- Orientation
- World position
- Carriages
- Consist wide cargo
Driving the train
Schedules
Doors and body
Links
The whole railway
Reacting to changes
Programs and reference
Start here
Controlling the plate
Automatic modes
Reading the turntable
Reference