Determining vehicle direction on roads

Find tutorials, documentation, and resources for creating and using TheoTown plugins.
User avatar
CommanderABab
AB
Reactions:
Posts: 11269
Joined: 07 Jun 2016, 19:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Determining vehicle direction on roads

Post by CommanderABab »

How to change the standard movement on roads:

Remember, arrays start with 0. :)
innerr.png

Subtile Order of Each Road Tile:

..........❌
.....❌ 2 ❌
.❌ 0 ❌ 3 ❌
.....❌ 1 ❌
..........❌


Moving direction is the sum of:
(This is from one of the subtiles above; a vehicle has reached this spot, the sum equals the possible directions it can go from here.)
↘️ 1
↗️ 2
↖️ 4
↙️ 8

So, "No direction" would be 0. Thus the vehicle would stop and most likely despawn. All directions would be 15 (for intersections).

An example of dirs for a two way road (24 number array):
(Dirs need to be provided for the frame in the comments, the others are determined from these)

Code: Select all

    "dirs":[
      12,9,3,6 , //0
      1, 1, 8,4,  //1
   
      1,1, 8, 2,  //3
  
      9,9,6,6, //5
    
      1, 3, 12, 6,  //7
  
      13,11,14,7 //15
    ]
An example of dirs for a one way road (64 number array):
(One for each of the first 15 road frames, the others are adapted from these.)

Code: Select all

      "dirs":[
       0,0,0,0,
       1,1,1,1,
       2,2,2,2,
       1,1,9,1,
       4,4,4,4,
       9,9,3,3,
       3,2,2,2,
       3,3,3,3,
       8,8,8,8,
       3,3,1,1,
       6,3,6,3,
       3,3,3,3,
       9,8,9,8,
       9,9,9,9,
       6,6,6,6,
       11,11,11,11
    ]
Note: the numbers in these examples are from my b3.plugin, which allows non-standard road movements so that cars can switch lanes across 3 or more lanes from the inner 2 way road straight sections across the straight sections of the one way roads placed adjacent. Thus, the cars may be seen driving off the side of ramps. :)
You do not have the required permissions to view the files attached to this post.
my avatar:
User avatar
CommanderABab
AB
Reactions:
Posts: 11269
Joined: 07 Jun 2016, 19:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by CommanderABab »

Image


So, you may see the t intersection directions better. :)

7,11,13,14 above are the t intersections. The yellow line though the center has breaks instead of being solid.
my avatar:
User avatar
Mg3094066
Inhabitant of a Supercluster
Reactions:
Posts: 3217
Joined: 27 May 2017, 23:50
Location: Venezuelan Republic of Mexico
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by Mg3094066 »

Aaaaaaa my head will exlode D:
I threw my dignity to trash and downloaded Free Fire... But someway i liked it ":'D

But i think it was too early to celebrate... my internet runs at 8kb...

Just wait another month... :bb
User avatar
CommanderABab
AB
Reactions:
Posts: 11269
Joined: 07 Jun 2016, 19:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by CommanderABab »

CommanderABab wrote: 20 Jul 2018, 02:25 How to change the standard movement on roads:

Remember, arrays start with 0. :)
Image


Subtile Order of Each Road Tile:

..........❌
.....❌ 2 ❌
.❌ 0 ❌ 3 ❌
.....❌ 1 ❌
..........❌


Moving direction is the sum of:
(This is from one of the subtiles above; a vehicle has reached this spot, the sum equals the possible directions it can go from here.)
↘️ 1
↗️ 2
↖️ 4
↙️ 8

So, "No direction" would be 0. Thus the vehicle would stop and most likely despawn. All directions would be 15 (for intersections).

An example of dirs for a two way road (24 number array):
(Dirs need to be provided for the frame in the comments, the others are determined from these)

Code: Select all

    "dirs":[
      12,9,3,6 , //0
      1, 1, 8,4,  //1
   
      1,1, 8, 2,  //3
  
      9,9,6,6, //5
    
      1, 3, 12, 6,  //7
  
      13,11,14,7 //15
    ]
An example of dirs for a one way road (64 number array):
(One for each of the first 15 road frames, the others are adapted from these.)

Code: Select all

      "dirs":[
       0,0,0,0,
       1,1,1,1,
       2,2,2,2,
       1,1,9,1,
       4,4,4,4,
       9,9,3,3,
       3,2,2,2,
       3,3,3,3,
       8,8,8,8,
       3,3,1,1,
       6,3,6,3,
       3,3,3,3,
       9,8,9,8,
       9,9,9,9,
       6,6,6,6,
       11,11,11,11
    ]
Note: the numbers in these examples are from my b3.plugin, which allows non-standard road movements so that cars can switch lanes across 3 or more lanes from the inner 2 way road straight sections across the straight sections of the one way roads placed adjacent. Thus, the cars may be seen driving off the side of ramps. :)
my avatar:
User avatar
CommanderABab
AB
Reactions:
Posts: 11269
Joined: 07 Jun 2016, 19:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by CommanderABab »

Code: Select all

    "dirs":[
      12,9,3,6 , //0
      1, 1, 8,4,  //1
      1,1, 8, 2,  //3
      9,9,6,6, //5
      8, 1, 6, 6,  //7
      8,1,4,2 //15
    ]

Where will it go?

:)
my avatar:
User avatar
CommanderABab
AB
Reactions:
Posts: 11269
Joined: 07 Jun 2016, 19:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by CommanderABab »

Currently used in green road special:

Code: Select all

    "dirs":[
      12,9,3,6 , //0
      1, 1, 8,4,  //1
      1,1, 8, 2,  //3
      9,9,6,6, //5
      9, 1, 6, 6,  //7
      8,1,4,2 //15
    ]
Screenshot_20190704-054947.jpg
You do not have the required permissions to view the files attached to this post.
my avatar:
User avatar
Lakan Haraya
Metropolitan
Reactions:
Posts: 131
Joined: 28 Mar 2019, 07:34
Location: Philippines
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by Lakan Haraya »

CommanderABab wrote: 06 Jun 2019, 00:40

Code: Select all

    "dirs":[
      12,9,3,6 , //0
      1, 1, 8,4,  //1
      1,1, 8, 2,  //3
      9,9,6,6, //5
      8, 1, 6, 6,  //7
      8,1,4,2 //15
    ]

Where will it go?

:)
Answer key ;)
Conversion to moving directions
↖&↙,↘&↙,↗&↖,↘&↗ //0 (frame 0)
↘,↘,↙,↖ //1 (frame 1)
↘,↘,↙,↗ //3 (frame 3)
↘&↙,↘&↙,↗&↖,↗&↖ //5 (frame 5)
↙,↘,↗&↖,↗&↖ //7 (frame 7)
↙,↘,↖,↗ //15 (frame 15)
:calc
I think frame 0 won't spawn in this moving directions, frame 1 looks like a U-turn slot, frame 3 is a 2-way road turning to the perpendicular row of tiles, frame 5 seems to be a 2-way road bounded intersection for directions 2 ↗ (for 4 ↖) and 8 ↙ (for 1 ↘), frame 7 is more like these sequence... ↙,↘,↖↗,↖↗ ... :)
Frame 15 is fully bounded intersection (I mean, the vehicles will only turn right in the corner)
:bt
To illustrate:
received_1384531225019585-1.jpg
You do not have the required permissions to view the files attached to this post.
"ᜀᜃᜓ ᜀᜅ᜔ ᜁᜌᜓᜅ᜔ ᜑᜇᜌ"
CEO of Haráya Motors

“TheoTown Philippines Council”
“Kapulungan Ng Mga Nagkakaisang Lungsod”
User avatar
CommanderABab
AB
Reactions:
Posts: 11269
Joined: 07 Jun 2016, 19:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by CommanderABab »

I'm glad that you are taking interest. :)

Frame 0 is just a single road tile unconnected. The idea here is if a car spawns here, it will move to an adjacent road if available.

Note my restored post above showing what I currently use in Green Road Special.

You are correct about frame 15.

Frame 1 is the end section of the road.

Frame 3 is the curve of the road.

Frame 5 is the straight of the road, connected on both ends. The idea here is that this two way section can be used as a median section between two one way spans. Cars can thus move to the one way spans also, in addition to going straight.

You are correct about frame 7 as you quoted it, but in the actual plugin, cars can also go straight instead of being forced to turn right. But I still do not allow the left turn. And, on the far side of the T, it still behaves as the straight section.
my avatar:
User avatar
Lakan Haraya
Metropolitan
Reactions:
Posts: 131
Joined: 28 Mar 2019, 07:34
Location: Philippines
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by Lakan Haraya »

I thought about it one night... I knew it!
It is interesting for traffic management and I think it could be a helpful tool to create real-life gas station in the game... I mean, passing cars beneath the station's roof... :/
"ᜀᜃᜓ ᜀᜅ᜔ ᜁᜌᜓᜅ᜔ ᜑᜇᜌ"
CEO of Haráya Motors

“TheoTown Philippines Council”
“Kapulungan Ng Mga Nagkakaisang Lungsod”
User avatar
choggoba
Townsman
Reactions:
Posts: 49
Joined: 20 Jul 2018, 06:30
Location: Korea
Plugins: Showcase Store

Platform

Re: Determining vehicle direction on roads

Post by choggoba »

I have a question.
1. Why did you define only 0,1,3,5,7,15 frames?
2. May I have the frame number of 16 one way road?
I love my hometown. :)

I don't speak English well. Please understand me. ;)
User avatar
ian`
Metropolitan
Reactions:
Posts: 117
Joined: 04 Apr 2020, 15:36
Location: 日本
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by ian` »

choggoba wrote: 08 Jul 2020, 22:32 I have a question.
1. Why did you define only 0,1,3,5,7,15 frames?
I think there are the first number of road rotation frames.

Code: Select all

0              // haven't rotation frames
1 - 2 - 4 - 8
3 - 6 - 9 - 12
5 - 10
7 - 11 - 13 14
15
2. May I have the frame number of 16 one way road?
Yes, just count the frames from 1 not 0. lol
If you mean there are be more than 64 arrays, i think you can't and what for is it?
:bc
User avatar
mbetixz
Villager
Reactions:
Posts: 13
Joined: 26 Mar 2019, 21:29
Location: Indonesia
Plugins: Showcase Store
Version: Beta

Platform

Re: Determining vehicle direction on roads

Post by mbetixz »

thanks for awesome tutorial, its will be helpful now 😊
Do anything you want, but remember KARMA IS REAL!!
i
imajoke
Inhabitant of a Conurbation
Reactions:
Posts: 529
Joined: 27 Oct 2019, 00:39
Plugins: Showcase Store
Version: Beta

Platform

Re: Determining vehicle direction on roads

Post by imajoke »

Can I have the dirs for the actual one way road? I still want to make a road where cars can pass (I dont care about if its safe for them or not)
Eugh. I remembered this account existed and all I did.
I'm a better person now. Most likely to stay inactive.
Awesome community by the way y'all are peak 🗣️🗣️

The YouTube account isn't mine anymore by the way, a different family member uses it now.
User avatar
CERRERA
Townsman
Reactions:
Posts: 48
Joined: 25 Jan 2020, 04:19
Location: Philippines
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by CERRERA »

Hello
I need help
Its possible to make my diagonal" as half way road
one way.png


When I try to make 1 way diagonal this was happened
Bug.jpg
You do not have the required permissions to view the files attached to this post.
Everything you can imagine is real
User avatar
burgernamn
Inhabitant of a Megacity
Reactions:
Posts: 173
Joined: 15 Apr 2022, 08:32
Plugins: Showcase Store

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by burgernamn »

im losing braincells every minute i try to understand this
im more active on my discord
G
Guest
Reactions:

Re: Determining vehicle direction on roads

Post by Guest »

Wekabu city wrote: 14 Jan 2023, 16:33
Show
id : adjacency
0 = None
1 = South
2 = East
3 = South and east
4 = North
5 = North and south
6 = North and east
7 = North and south and east
8 = West
9 = West and south
10 = West and east
11 = West and south and east
12 = West and north
13 = West and north and south
14 = West and north and east
15 = West and north and south and east
Basically all four cardinal directions are a bit. 1 is south, 2 is east, 4 is north and 8 is west. By adding the bits you get the frame id.
arrowframes.png
You do not have the required permissions to view the files attached to this post.
User avatar
Marvel
Metropolitan
Reactions:
Posts: 111
Joined: 29 Nov 2020, 06:47
Location: Indonesia
Plugins: Showcase Store
Version: Beta

Re: Determining vehicle direction on roads

Post by Marvel »

CommanderABab wrote: 20 Jul 2018, 02:25 How to change the standard movement on roads:

Remember, arrays start with 0. :)

innerr.png

Subtile Order of Each Road Tile:

..........❌
.....❌ 2 ❌
.❌ 0 ❌ 3 ❌
.....❌ 1 ❌
..........❌


Moving direction is the sum of:
(This is from one of the subtiles above; a vehicle has reached this spot, the sum equals the possible directions it can go from here.)
↘️ 1
↗️ 2
↖️ 4
↙️ 8

So, "No direction" would be 0. Thus the vehicle would stop and most likely despawn. All directions would be 15 (for intersections).

An example of dirs for a two way road (24 number array):
(Dirs need to be provided for the frame in the comments, the others are determined from these)

Code: Select all

    "dirs":[
      12,9,3,6 , //0
      1, 1, 8,4,  //1
   
      1,1, 8, 2,  //3
  
      9,9,6,6, //5
    
      1, 3, 12, 6,  //7
  
      13,11,14,7 //15
    ]
An example of dirs for a one way road (64 number array):
(One for each of the first 15 road frames, the others are adapted from these.)

Code: Select all

      "dirs":[
       0,0,0,0,
       1,1,1,1,
       2,2,2,2,
       1,1,9,1,
       4,4,4,4,
       9,9,3,3,
       3,2,2,2,
       3,3,3,3,
       8,8,8,8,
       3,3,1,1,
       6,3,6,3,
       3,3,3,3,
       9,8,9,8,
       9,9,9,9,
       6,6,6,6,
       11,11,11,11
    ]
Note: the numbers in these examples are from my b3.plugin, which allows non-standard road movements so that cars can switch lanes across 3 or more lanes from the inner 2 way road straight sections across the straight sections of the one way roads placed adjacent. Thus, the cars may be seen driving off the side of ramps. :)
Isnt the frame 0 supposed to be 12,9,6,3 instead of 12,9,3,6 ?
User avatar
CommanderABab
AB
Reactions:
Posts: 11269
Joined: 07 Jun 2016, 19:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by CommanderABab »

Marvel wrote: 23 Jun 2025, 06:11
CommanderABab wrote: 20 Jul 2018, 02:25 How to change the standard movement on roads:

Remember, arrays start with 0. :)

innerr.png

Subtile Order of Each Road Tile:

..........❌
.....❌ 2 ❌
.❌ 0 ❌ 3 ❌
.....❌ 1 ❌
..........❌


Moving direction is the sum of:
(This is from one of the subtiles above; a vehicle has reached this spot, the sum equals the possible directions it can go from here.)
↘️ 1
↗️ 2
↖️ 4
↙️ 8

So, "No direction" would be 0. Thus the vehicle would stop and most likely despawn. All directions would be 15 (for intersections).

An example of dirs for a two way road (24 number array):
(Dirs need to be provided for the frame in the comments, the others are determined from these)

Code: Select all

    "dirs":[
      12,9,3,6 , //0
      1, 1, 8,4,  //1
   
      1,1, 8, 2,  //3
  
      9,9,6,6, //5
    
      1, 3, 12, 6,  //7
  
      13,11,14,7 //15
    ]
An example of dirs for a one way road (64 number array):
(One for each of the first 15 road frames, the others are adapted from these.)

Code: Select all

      "dirs":[
       0,0,0,0,
       1,1,1,1,
       2,2,2,2,
       1,1,9,1,
       4,4,4,4,
       9,9,3,3,
       3,2,2,2,
       3,3,3,3,
       8,8,8,8,
       3,3,1,1,
       6,3,6,3,
       3,3,3,3,
       9,8,9,8,
       9,9,9,9,
       6,6,6,6,
       11,11,11,11
    ]
Note: the numbers in these examples are from my b3.plugin, which allows non-standard road movements so that cars can switch lanes across 3 or more lanes from the inner 2 way road straight sections across the straight sections of the one way roads placed adjacent. Thus, the cars may be seen driving off the side of ramps. :)
Isnt the frame 0 supposed to be 12,9,6,3 instead of 12,9,3,6 ?
Thank you for bringing this to my attention.
For an immediate turn around, it appears that you are right.
Maybe also 9,12,3,6 so that cars circle the square before exiting (which was probably my intention) .:)
User avatar
Matthew H
Settler
Reactions:
Posts: 7
Joined: 26 Mar 2025, 04:18
Location: Vacnvouer, BC, Canada
Plugins: Showcase Store

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by Matthew H »

from what i am understanding:
each road has up to 4 connections to the surrounding tiles (therefore 16 different combinations of connections)
each tile has 4 subtiles that determine how cars move to and from each different road tile
these subtiles also have up to four connections each, again creating 16 combinations of the connections, in the same order
if we assume that each of these connections is visualized as a line from the center of the subtile to the edge of the subtile, then:
vehicles can travel (in either direction depending on if you have left or right hand traffic and which subtile it is on) between subtiles either if (a valid connection is one where the subtile has a line from the shared edge with the other subtile)(vehicles travel from the incoming subtile to the outgoing subtile):
1) both subtiles have a valid connection (i.e. BOTH have a line that starts on their shared edge and ends in their center)
2) if the outgoing subtile has a valid connection regardless if the incoming subtile has a valid connection
3) if the incoming subtile has a valid connection regardless if the outgoing subtile has a valid connection
4) if either the outgoing, incoming, or both have a valid connection

so is it 1,2,3, or 4?
also am i completely off?

Resized_20250625_121932.jpeg
You do not have the required permissions to view the files attached to this post.
User avatar
Matthew H
Settler
Reactions:
Posts: 7
Joined: 26 Mar 2025, 04:18
Location: Vacnvouer, BC, Canada
Plugins: Showcase Store

Plugin Creator

Platform

Re: Determining vehicle direction on roads

Post by Matthew H »

CommanderABab wrote: 20 Jul 2018, 02:25 How to change the standard movement on roads:

Remember, arrays start with 0. :)

innerr.png

Subtile Order of Each Road Tile:

..........❌
.....❌ 2 ❌
.❌ 0 ❌ 3 ❌
.....❌ 1 ❌
..........❌


Moving direction is the sum of:
(This is from one of the subtiles above; a vehicle has reached this spot, the sum equals the possible directions it can go from here.)
↘️ 1
↗️ 2
↖️ 4
↙️ 8

So, "No direction" would be 0. Thus the vehicle would stop and most likely despawn. All directions would be 15 (for intersections).

An example of dirs for a two way road (24 number array):
(Dirs need to be provided for the frame in the comments, the others are determined from these)

Code: Select all

    "dirs":[
      12,9,3,6 , //0
      1, 1, 8,4,  //1
   
      1,1, 8, 2,  //3
  
      9,9,6,6, //5
    
      1, 3, 12, 6,  //7
  
      13,11,14,7 //15
    ]
An example of dirs for a one way road (64 number array):
(One for each of the first 15 road frames, the others are adapted from these.)

Code: Select all

      "dirs":[
       0,0,0,0,
       1,1,1,1,
       2,2,2,2,
       1,1,9,1,
       4,4,4,4,
       9,9,3,3,
       3,2,2,2,
       3,3,3,3,
       8,8,8,8,
       3,3,1,1,
       6,3,6,3,
       3,3,3,3,
       9,8,9,8,
       9,9,9,9,
       6,6,6,6,
       11,11,11,11
    ]
Note: the numbers in these examples are from my b3.plugin, which allows non-standard road movements so that cars can switch lanes across 3 or more lanes from the inner 2 way road straight sections across the straight sections of the one way roads placed adjacent. Thus, the cars may be seen driving off the side of ramps. :)
also is it possible to make a one way road with only one lane using this?