The railroads use ABS signals (automatic block signals) to control the train traffic and the signals use block detection to display the proper information to the trains. A block is a section of track of the railroad. I want a system where I can detect when a block is occupied by a train.
I have tried to use detector parts at each end of a block and it works fine, except when a train is able to leave the block by changing tracks without passing the detector parts.
Is there other ways I can detect if a train is in a block?
In real life the track is powered with energy and when the wheels are on the track it bridges the rails and triggers a relay indicating that the block is occupied.
One thing you could do is have a invisible, no-collided part on the block of the track that you want to identify whether or not it is occupied. Inside that part, you can put a script that when it is touched, if the item touching it is a train, then you can update that block to say it is occupied. here is some pseudo code as to what this might look like:
block.touched:Connect(funciton(hit)
if hit is a train then
occupied = true
end
I would recommend making occupied a bool value instance that is a child to the block of rails (not invisible part b/c that is not what is being occupied), so that it is accessible by other scripts if it needed to be.
Edit: You would also need to add a event on the touch ending, to update the occupied value, but it would look very similar - hope this helps!
I think this system should work as long as most of it is covered, so as long as its not a 90 degree turn it should be fine to just cover most of the track.
Another idea you could do is put the code inside the tracks themselves, but that would only work if it was one part/union, which could make some funky hitboxes. You could achieve a similar result by making unions out of the invisible parts, which would probably work better than making unions out of tracks if they aren’t unions already.
Edit: sorry for the late response, let me know if you have any other questions!
I wish I can use the idea but I have 90 degree curves in the track, some even more. I would like the block detection to be separated by normal sized parts. But thanks for helping.
I’m gonna try and experiment with the unions though.
Hmm, why not just put the part but increase it’s size, unless you’d need to detect multiple Thomas the tank engine’s, this should work alright.
Also try using a while true loop (dont forget the wait()) so it can constantly check if there’s Gordon on it.
(Note: The name’s are not to make fun of your game (actually I’d like to play it but I’m currently banned), this subject just brought nostalgia of the classic)
Ah so it is boolean then, good so a while true loop could work nicely if set around .1 and .5, without concerning another engine entering the space and “tripping” or breaking a script
Loops only to constantly check if the engine is still on that platform, cause ya know observing the reactions in a script, functions with the touch event tend to deactivate themselves if the part or humanoid it’s trying to detect stays absolutely still, which can be a problem for you.
oh ok I haven’t experienced this yet with my testing though but if it become a problem il change it to a loop. Im also gonna mark the first post as solution because they kind of introduced the answer.
Sounds good, hope I helped ye out with my minimal but sufficient experience on scripting, if anything I think you can repost on this forum or just message me directly