Here are scripts to build vertex paths for EasyRoads3d spline road paths, including sample scripts to implement path following.
EasyRoads3D: https://assetstore.unity.com/packages/tools/terrain/easyroads3d-pro-v3-469
Inspired by API of Bezier Path Creator: https://assetstore.unity.com/packages/tools/utilities/b-zier-path-creator-136082
- Add
ERNetworkVertexPathCreator
to ER Road Network It will add (if not exists)ERNetworkVertexPathCreator
andERPathAdapter
to anyERModularRoad
from children.ERNetworkVertexPathCreator
will create vertex path based on ER spline path with givenangleThreshold
andscanStep
ERPathAdapter
will provide API to align objects along the path and calculate nearest position and distance. - Add
ERPathCamera
(sample script) to anyCamera
to follow given road path (linkmodularRoad
to anyERModularRoad
)
Input:- ERModularRoad - road to follow (will search for ERPathAdapter component and use it)
- SpeedMs - velocity in meters per second
- Add DummyHelperPathController (another sample script) to any object to move it along the path
Input:
ERModularRoad
- road object to followspeedMs
- move velocity in m/spositionByClosestPoint
- position object by closest point or by closest distancealignToPath
- enable/disable path following (useful to check path alignment for objects out of path in different configs)
Lets review sample config - it will contain single ER Road Network with Road, Camera to move along the Road and two GameObjects which will also move along road path.
Required config steps are described by following screenshots
Vertex paths gizmos are shown in Play mode:
ERNetworkVertexPathCreator
- scan Road Network for roads, attachERPathToVertexPathWrapper
andERPathAdapter
to each road (if not exists)ERPathToVertexPathWrapper
- builds vertex path from ER spline path for given road (by default withangleThreshold
andscanStep
set for ERNetworkVertexPathCreator). IfangleThreshold
orscanStep
must be customized,ERNetworkVertexPathCreator
can be manually attached to the roadERPathAdapter
- provide API to follow vertex path
Vector3 GetPointAtDistance(float distance)
Quaternion GetRotationAtDistance(float distance)
Vector3 GetDirectionAtDistance(float distance)
float GetClosestDistanceAlongPath(Vector3 p)
Vector3 GetClosestPointOnPath(Vector3 p, out float closestDistance)
Vector3 GetClosestPointOnPath(Vector3 p)
- I'm not using crossings, therefore linked roads are not supported
- All methods distance-related methods are map distance to current road bounds (from zero to total path distance) so you can use negative distance or distance much more than total road length