Spot on the monorail system I've been working on. It relies on 10 meter long track pieces that are named simply "Track" to guide itself along them using a sensor.
However there are major issues with this and monorail/train systems in general, as described below.To explain briefly, what this code does is sense for any track pieces in front of it and then, using a for loop, move itself gently towards it. llSetPos works (as usually does in any case) by using llGetPos + final destination. In this case, it finds the distance between it's current position and the next track piece, divides that by 4 steps and then adds that division to it's current position. Half way through it sets it's rotation to that of the track piece.
Code:
vector m_NEXTPOS;
vector m_NEXTFWD;
rotation m_NEXTROT;
integer m_STEPS = 4;
motionTo(vector dest,rotation rot) {
integer i;
vector currentpos = llGetPos();
vector step = (dest - currentpos) / m_STEPS;
for (i = 1;i <= m_STEPS; i++) {
if (i == (m_STEPS / 2)) {
llSetRot(rot);
}
llSetPos(currentpos + (step * i));;
}
}
default {
state_entry() {
llSensorRepeat("Track",NULL_KEY,PASSIVE,10,PI/4,1);
}
sensor(integer n) {
m_NEXTPOS = llDetectedPos(0);
m_NEXTROT = llDetectedRot(0);
m_NEXTFWD = llRot2Fwd(m_NEXTROT) / 10;
motionTo(m_NEXTPOS + m_NEXTFWD,m_NEXTROT);
}
}
Incomplete code as it does not make any stops or anything. Easily done with different names of track I guess.
However, this and any other method of train/monorail (physical or nonphysical) does
NOT WORK cross region, which limits your train system to just one region. llSetPos fails silently when moving an object across a boundary and physical objects crossing are.. just a nightmare. The only possible solution to this is a
megaregion but personally I do not recommend them as they are incomplete, lack parcel support, tend to break and are hell to teleport into.
Hope this all helps :U