Skip to main content

WayPointPath

A class in Root.Township, the global namespace.

A networked, saved path of points with rotations that other code samples by distance (IPositionRotationPath). The server sends the points to each player who connects.

Constructors​

MemberWhat it is
WayPointPath()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

5 private and internal fields
MemberWhat it is
private float[] lengthsLength of each segment between points.
private Vector3[] positionsBacking field for Positions.
private Quaternion[] rotationsBacking field for Rotations.
private MethodSync syncPositionsMethod sync that sends the points to players.
private float totalDistanceTotal path length, used for normalised lookups.

Properties​

MemberWhat it is
Vector3[] Positions { get; set; }Point positions in world space. Setting it doesn't recompute lengths or resync.
Quaternion[] Rotations { get; set; }Point rotations, one per position.

Methods​

MemberWhat it is
static void GetPointFromArray(Vector3[] positions, Quaternion[] rotations, float[] lengths, ref float distance, out Vector3 position, out Quaternion rotation)Static: walks the segment lengths to find the position and rotation at a distance along the points, clamped to the ends. PresetWayPointPath uses it too.
override void Initialize()Sets up the method sync that sends the points.
override void InitializeAsServer(SpawnData spawnData)Server: works out segment lengths from the loaded points.
override void OnConnected(Player player)Server: sends the points to a joining player.
4 private and internal methods
MemberWhat it is
private void IPositionRotationPath.GetPosition(float value, out Vector3 position, out Quaternion rotation, bool isNormalized)Gets the point at a distance along the path, or at a 0 to 1 fraction of it when isNormalized is true.
private void OnDrawGizmosSelected()Draws the path in the editor.
private void SetupDistances()Works out each segment length and the total length.
private void SyncPositions(IPlayer player, Stream stream)Writes or reads the points and rotations (15 at most). Clients rebuild the lengths after reading.