Hi, thanks to this community I got my tramcar working even with opening doors, linked to the tram when moving
now I sure want to step into having a tram performing a curve:
Assuming I can't simply link my brushmodel to a chain of pathnodes (as it works for models), I made a chain of script_origins.
They're named node0 - node10
Now: Before, it was enough to use this code
Code:
tram _MoveTramFromTo (node0, node1);
tram _MoveTramFromTo (node1, node2);
...
tram _MoveTramFromTo (node10, node11);
}
_MoveTramFromTo (na, nb) // function for moving tram between 2 nodes with constant speed
{
dist = distance(na.origin,nb.origin); // finding out what the distance between next 2 nodes is
time = (dist/250); //computing the time needed for moving the tram on given distance with speed 250 units/second
self MoveTo( nb.origin, time, 0, 0);
self RotateTo( VectorToAngles( na.origin - nb.origin ), time );
self waittill ("movedone");
}
I kept on calling this function to every pair of neighboring nodes until i got to the last node, but this way my code got very long and very unclear - I would like to make a loop that will increase the nodenumber by itself, there are two ways I imagine to do that, but I'm not sure which is better or possible at all:
1)making an array of my nodes (nodes[]) and then adjust my function for abstract entity names:
Code:
for (i=0, i<nodes.size; i++)
{
dist = distance(nodes[i].origin,nodes[i+1].origin);
time = (dist/250);
self MoveTo( nodes[i+1].origin, time, 0, 0);
self RotateTo( VectorToAngles( nodes[i+1]origin - nodes[i].origin ), time );
self waittill ("movedone");
}
2) the second method would be better but as far as i have been trying, it seems not possible:
If I can refer to entity's target as to entity.target
and
If I can refer to entity's origin as to entity.origin
then
It would be wonderful if i cound merge this and write entity1.target.origin, meaning "the origin of an entity this entity1 is pointing at":
then I could use something like this
initialnode = node0; // a node I start from in first loop
node_count = 10;
for (i=0 ; i
{
dist = distance(initialnode.origin,initialnode.target.origin); //since in Radiant, I made my node0 be targetting to node1 etc., node0.target would be node1 and I could make referrence directly to its origin
time = (dist/250);
self MoveTo( initialnode.target.origin, time, 0, 0);
self RotateTo( VectorToAngles( initialnode.target.origin - intitialnode.origin ), time );
self waittill ("movedone");
initialnode = initialnode.target // by this, I transform the target from last
loop into the initialnode for the next loop (for first loop, preset node0 would change to node1 and so on) This way, I move along the path...
}
in spite of the fact this code is a bit confusing for the human (or for myself, definitely), it would move the tram safely along the entire path, if targetnames and targets are set properly... the only thing left to do for the user would be setting the total number of nodes making the path to ensure appropriate number of loops
unfortunately, although the script doesn't issue any bad syntax errors, it doesn't work either,
but still, there is some hope for it to work...
I only somehow stopped believing that "entity.target.origin" is valid expression for adressing the origin of an entity, that is syntactically nothing more than a target to some another entity. Is that possible or not?
also, when I used the old way - calling the function on a pair of nodes with increasing number - the tram stopped for a moment on each node before the speed of next move was computed - it totally broke the otherwise sufficient result - I would need something like
time = 1; //having time set for the first move
function()
{
-using pre-set time (1) to move and rotate from node0 to node1 (with no waittill ("movedone");)
-computing time for moving the following section (node1 to node2)
-wait until the movement ends
-move to next section with time already known, rewriting the initial time = 1 or another values, computed in previous loops ...
}
since my map is nothing more than a Stalingrad's worker going to night shift the day the Battle for Stalingrad started and commutes there by a tram, finetuning this script is crucial...
thanks for any help
Ramidus
edited on Nov. 8, 2011 01:56 pm by RAMIDUS
edited on Nov. 8, 2011 01:57 pm by RAMIDUS