Preparation
First of all you need to create the different colored parts in this picture:
[Blocked Image: http://www.train-fever.net/index.php/Attachment/14704-TrainFeverRodAnimation-jpg/]
- One Wheel (blue)
- One Piston (red)
- One Connection Rod (yellow)
- One Coupling Rod (green)
You don't need need all of the parts to make them move, if you have let's say a shunter with a coupling rod, you can only create that one.
Each part should be mirrored to the other side of the locomotive so you don't need to create more models just to have the coupling rod on the opposite side at a different position (like they are in real life).
You can basically have a different origin for all of your single meshes, but then you would have to enter the different positions of the mesh in the group file. Let's keep it simple and have them all set up like in the picture above.
Animating the Piston
Open the piston's .msh file, find
and replace it with
local vec2 = require "vec2"
local vehicleutil = require "vehicleutil"
function data() return {
animations = { drive = vehicleutil.makePistonAnim(vec2.new(X1, Y1), vec2.new(X2, Y2), vec2.new(X3, Y3)) },
Replace X1 and Y1 with the position of WheelCenter in meters.
Replace X2 and Y2 with the position of WheelPos0 in meters.
Replace X3 and Y3 with the position of PistonPos0 in meters.
In this case it's:
X1 = 0
Y1 = 0.682405
X2 = 0
Y2 = 0.47
X3 = 2.26
Y3 = 0.9
Make sure you use as exact as possible values, otherwise the position of the rods won't match the position of the wheel after some time!
Animating the Coupling Rod
Open the coupling rod's .msh file, find
and replace it with
local vec2 = require "vec2"
local vehicleutil = require "vehicleutil"
function data() return {
animations = { drive = vehicleutil.makeCouplingRodAnim(vec2.new(X1, Y1), vec2.new(X2.Y2)) },
Replace X1 and Y1 with the position of WheelCenter in meters.
Replace X2 and Y2 with the position of WheelPos0 in meters.
In this case it's:
X1 = 0
Y1 = 0.682405
X2 = 0
Y2 = 0.47
Make sure you use as exact as possible values, otherwise the position of the rods won't match the position of the wheel after some time!
Animating the Connection Rod
Open the connection rod's .msh file, find
and replace it with
local vec2 = require "vec2"
local vehicleutil = require "vehicleutil"
function data() return {
animations = { drive = vehicleutil.makeConnectingRodAnim(vec2.new(X1, Y1), vec2.new(X2, Y2), vec2.new(X3, Y3)) },
Replace X1 and Y1 with the position of WheelCenter in meters.
Replace X2 and Y2 with the position of WheelPos0 in meters.
Replace X3 and Y3 with the position of PistonPos0 in meters.
In this case it's:
X1 = 0
Y1 = 0.682405
X2 = 0
Y2 = 0.47
X3 = 2.26
Y3 = 0.9
Make sure you use as exact as possible values, otherwise the position of the rods won't match the position of the wheel after some time!
That's it!
Once you import the rest of the locomotive properly, you're done.
If you need any help regarding this topic, leave a comment.
Choo choo!