Jump to content
Sign in to follow this  
bana

Train Driving

Recommended Posts

I am trying to create a moving train for a cutscene intro.

- I have attached a civilian car to the locomotive (low enough to move)

- I have set waypoints for the car along the railroad track (close together)

- Set the car to "careless"

Whatever I seem to do with waypoint settings, the car doesn't stick to the tracks. It will move in a snake like fashion on and off the tracks from one waypoint to another.

Any suggestions as to how to make it move in a straight line along the tracks?

Cheers

Share this post


Link to post
Share on other sites

You can forget vehicles they won't go where you want.

The only way would be to script it using loops and incrementing setpos which could take a while. You would also have to set the direction.

I don't know if it's possible to record positons and store them for later use that would work as you could drive the track and store the data.

If all you need is for it to go in a straight line you could try the velocity command although it doesn't seem to work on everything and you would have to keep calling it in a loop.

Share this post


Link to post
Share on other sites

Just a crazy idea, but can you attach it to a car, and do some setVelocity to the car?

Edit: above didn't work

Try this instead.

Edited by Mike84

Share this post


Link to post
Share on other sites

It may be possible, I tried it with a plane attached to a truck but it wasn't reliable.

Share this post


Link to post
Share on other sites
A lot of math.

No, its just an arseload to make on the whole ;)

The simplest way if used in a cutscene is to make it fixed speed and move the train at a fixed angle with a quick loop and small increment, then when it get within a very close distance of a marker (ie a marker array used as waypoints), you just change direction with the marker angle. The train would veer off course if you make a mistake and either check the marker to close or if you aim it wrong... A slightly more complicated thing to do is to automatically get the angle between the current and next marker.

The math involved in this is pretty minimal.

Share this post


Link to post
Share on other sites

I trying it like this: rail = position this nearestobject 962253; train setpos [getpos rail select 0, getpos rail select 1, 0.05]; train setDir (getdir rail); train setVelocity [(sin (getdir rail)*70), (cos (getdir rail)*70), 0];

But I dont find how get next rail position and direction.

Edit: They have change rail ID:s in 1.03. If you have 1.03 installed change object ID to 962536 if you want to see how train moving near Baloga station.

Edited by Cowboy_F

Share this post


Link to post
Share on other sites

Can't see anything happening Cowboy.

I did get the train going around the bend but it was very jerky using attachto and setdir.

Share this post


Link to post
Share on other sites
Can't see anything happening Cowboy.

Problem is car wheels. They dont fit in rails. Use M1A2, it works better. We need vechile with very wide wheels and no suspension.

Share this post


Link to post
Share on other sites

Ah I didn't realise you were attaching it to a vehicle.

Share this post


Link to post
Share on other sites

Thanks for the suggestions guys. I'm still having problems trying to get it to work. I would have tried doing a lot of getPos/setPos in a script but my maths is no good. that's why I'm trying attachTo. I've yet to try a tracked vehicle. Not giving up on this challenge yet.

Share this post


Link to post
Share on other sites

Hello all,

I also tried to get this train to drive and managed it finally, but there are many problems. Due to the tracks are sloped, you have to calculate the proper height to keep the train on the rails. Also, rails are stuck together often so it's a PITA to follow them.

I did it in a very (very, very) "dirty" way, bei setPos'ing the train object every 0.01 seconds to the new calculated position. Also the script is very dirty and *shudder* in sqs-format. (see below)

Please note that the object numbers may be outdated with patch 1.03. Well, if the tracks were flat (no slopes) and the rails would be correctly stuck together, it would be worth the time to write a clean script. But at this time, I've given up.

// check if all arguments are passed

if (count _this < 2) then { hintSilent "TRAIN SCRIPT ERROR\nThis script needs two arguments to work."; exit; };



//define the tracks

tracks = [];

tracks set [0,[042,043,041,046,045,047,016,017,015,162,163,164,167,165,166,168,169,170,171,173,174,172,175,177]];



// initialize main variables

_train = _this select 0;

_track = tracks select (_this select 1);



// preprocess tracks

for "_x" from 0 to ((count _track)-1) do {_track set [_x,[0,0] nearestObject ((_track select _x) + 962000)]}



// get start-object

_start = _track select 0;



// place the train on the rails

_train setPos [getPos _start select 0, getPos _start select 1, (getPos _start select 2) + 0.3];

_train setDir getDir _start;



// go train-driving



_r = 1;



#mainloop

if (_r == count(_track)) then { exit; }



_c = _track select _r;

_n = _track select _r+1;

_d = _train distance _n;

_l = _c distance _n;



if (_d > (_l/2)) then {_train setDir getDir _c} else {_train setDir getDir _n; _r = _r + 1};



_np = [_train,0.05,(getDir _train)] call BIS_fnc_relPos;

_train setPos [_np select 0, _np select 1];



hintSilent format ["current: %1(%5)\nnext: %2\nlength: %3\ndistance: %4",_c, _n, _l/2, _d, _r];



~0.01



goto "mainloop";



exit

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×