Modifiable voxel rail system concepts?

Started by
2 comments, last by GameObject 8 years, 6 months ago

I've been working on a railroad system for a voxel game I'm making but pretty much starting over from scratch again after my previous system has caused so many head aches. In my previous setup, user places voxel rails and as the train engine moved from one to the next, every time train ran it would scan several blocks ahead and built a list of rails. Each rail stored a list of coordinates that were open for connecting to other rails. The train engine would check to make sure each rail was connected by checking these coordinates between two rails to see if they match (two rails facing each other properly side by side) and if they do, the rail is connected so the train could move forward. I ran into problems when the rails were at higher or lower elevations which added more complexity.

I was thinking of adding some sort of waypoint system instead but I'm having trouble wrapping my head around this insofar of making sure the next waypoint is correct facing track to the previous waypoint. Essentially each track in the railroad would be a waypoint but the voxel rails need to be correct facing ones, otherwise for example you may have problems like a front facing track and left/right turn track which might not connect but the waypoint system would still flow forward.

Has anyone ever done anything similar or can provide any tips or an overview on what the best approach might be? The railway system is 3d space, modifiable, and the tracks can be placed and destroyed any time.

Advertisement

Thinking about it a bit, I would give each track piece (whether its single-voxel pieces or multi-voxel ones) a set of entrance/exit edges (Ill call these 'edges').

A voxel sized track piece would have 4 edges at bottom face and 4 at top face (8 total). Assuming alignment with voxel edges (you can use completely arbitrary edges in space, the idea still works).

Then, when a train enters a track piece, you must decide which edge to exit from. A straight/turn track, easy (theres just 1 option). Multi-way turns, just add some mechanism to switch between the potential directions.

Then, given the exit edge, find the matching entrance edge on whatever track piece comes next (on a horizontal track, just check the next voxel. If you have up/down slopes, might need to check the voxel below that one too). This is intuitive, when the trains wheels leave tracks at one point, they must check whether theres tracks ahead.

This gives you a sequence of edges the train must follow (maybe you use a spline or set of points to define the shape of track inside a track piece). Then just make the train follow that line, with some physics based on slope.

If no corresponding entrance edge is found for a given exit edge, you can either not allow the train to go that route (if theres alternatives), or trigger some derail event when the train gets there (or let it push through until it possibly lands on more rails)

If you want complete free-form rails (independent from voxels), do something similar, except instead of using voxels to define track pieces and find the next track piece, just use free-floating objects and arbitrary edge positionings for it. I would recommend this approach if a smooth ride is desireable (its going to be messy if you start hacking in smooth multi-block turns assembled from a hundred sub-blocks).

o3o

In my FreeRCT game, I have a collection of (multi-voxel) track pieces that the user can pick from. Connectivity between track-pieces is handled by an entry and exit connector, in some voxel. The rule is that the exit connector of the previous track piece must be equal to the entry connector of the next track piece.

I don't have hard rules on deciding the precise value (the game itself doesn't care other than being equal between pieces), but generally, you use direction of entry/exit, and orientation (banking direction, and position of the track-end in the voxel).

Thanks, I've updated my railsystem to do this. That was my initial approach but I just rewrote it today, seems to be working better now. Still a few kinks to work out but overall it's OK.

This topic is closed to new replies.

Advertisement