by cjbarnes5294 » Mon May 30, 2016 8:03 pm
- Code: Select all
do
local wheelPos = 0;
local wheelSlipFactor = 0;
local wheelLockup = false;
local function WheelPosition (time)
local speed = Call("GetSpeed");
local DRIVE_WHEEL_DIAMETER = 2; --m, change as required
local WHEEL_CIRCUMFERANCE = DRIVE_WHEEL_DIAMETER*math.pi();
--wheelslip
local wheelslip = Call("GetControlValue", "Wheelslip", 0); --add a wheelslip control to the engine blueprint, min value to 1 and max value to 2 or 3
local regulator = Call("GetControlValue", "Regulator", 0);
local reverser = math.abs(Call("GetControlValue", "Reverser", 0));
local trainBrake = Call("GetControlValue", "TrainBrakeControl", 0);
local BRAKE_APPLY_NOTCH = 0.2; --set to whatever the application starting notch is
if wheelslip > 1 and trainBrake < BRAKE_APPLY_NOTCH then
wheelSlipFactor = wheelSlipFactor + 2*regulator*reverser*time; --increase acceleration with more force ie.regulator*cut-off
if wheelSlipFactor > 1.5 then
wheelSlipFactor = 1.5;
end
wheelLockup = false;
elseif wheelslip > 1 and trainBrake >= BRAKE_APPLY_NOTCH then
wheelSlipFactor = 0;
wheelLockup = true; --crude form of wheelskid by stopping the animation
else
wheelSlipFactor = 0;
wheelLockup = false;
end
--wheel positioning
if math.abs(speed) > 0.01 and not wheelLockup then --TS physics are extremely noisy, so that when something should be moving absolutely still the acceleration rapidly oscillates around 0 m/s^2
local direction;
local reverser = Call("GetControlValue", "Reverser", 0);
if reverser >= 0 then
direction = 1;
else
direction = -1;
end
wheelPos = wheelPos + (speed + direction*wheelSlipFactor)*time;
if wheelPos > WHEEL_CIRCUMFERANCE then
wheelPos = wheelPos - WHEEL_CIRCUMFERANCE;
elseif wheelPos < 0 then
wheelPos = wheelPos + WHEEL_CIRCUMFERANCE;
end
end
end
local function WheelAnim ()
local NUM_OF_ANIM_FRAMES = 16; --change as required
Call("SetTime", <anim_name_in_engine_blueprint>, (wheelPos/WHEEL_CIRCUMFERANCE)*(NUM_OF_ANIM_FRAMES/30)); --assume the game runs all anims at 30fps
end
function AnimateWheels (time)
WheelPosition(time);
WheelAnim();
end
end
function Initialise ()
end
function OnControlValueChange ( name, index, value )
end
function Update (time)
AnimateWheels (time); --do for player locos and AI
end
That should do the trick. Note that without proper Newtonian force calculations and Coulomb's Law of Friction, and just using the core adhesion simulation, it's much harder to animate wheelslip convincingly, but I've done a basic form of wheelslip and skid animation that can be worked with for now.
Kind regards,
Chris
The Red Queen Hypothesis, applicable to train sim development?
"Here, you see, it takes all of the running you can do, to keep the same place."