DirectionConstrainedRandomMovement
A class in Root.Township, the global namespace.
Moves an object back and forth along one local direction to random points, picked by the server and synced to clients (for example bobbing or swaying props).
- Listed in Global namespace: C to D
- Inherits or implements
NetworkEntityBehaviour
Constructors
| Member | What it is |
|---|---|
DirectionConstrainedRandomMovement() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
14 private and internal fields
| Member | What it is |
|---|---|
private float aceleration | How fast speed ramps up after a new target; 0 means full speed at once. |
private Transform cachedTransform | Cached transform being moved. |
private float currentSpeedMultiplier | Current speed ramp, 0 to 1. |
private Vector3 direction | Local direction of travel (normalised). |
private AnimationCurve modulator | Curve for how far each step goes, as a share of the amplitude. |
private float movementAmplitude | Length of the line the object moves along. |
private float movementSpeed | Movement speed, or lerp rate when lerping. |
private bool moveWithLerp | Whether to ease with lerp instead of moving at a steady speed. |
private Vector3 movingTowards | Current target local position. |
private float nextSign | Which way the next step goes; flips each time. |
private MethodSync syncFull | Full position sync. |
private MethodSyncStruct<float> syncMovement | Target sync. |
private IUnityUpdateMethod updatePosition | The update registration. |
private bool usesNegativeValuesOnModulator | Whether the modulator is sampled from -1 to 1 instead of 0 to 1. |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Sets up the syncs and registers the server or client update. |
override void OnConnected(Player player) | Server: sends the current target. It sends to all chunks, not only the joining player. |
7 private and internal methods
| Member | What it is |
|---|---|
private void GetNewPosition() | Server: picks the next target along the direction, alternating sides, and sends it to clients. |
private void OnDestroy() | Removes the update registration. |
private void OnDrawGizmosSelected() | Draws the movement line in the parent's space. |
private void ServerUpdatePosition() | Server: picks a new target on arrival, then moves. |
private void SyncFull(IPlayer player, Stream stream) | Syncs current position and target as ratios along the line. Not sent anywhere in this class. |
private void SyncMovement(IPlayer player, Stream stream, float movingTowardsRatio) | Client: receives a new target ratio and restarts the speed ramp. |
private void UpdatePosition() | Moves toward the target, by lerp or at a steady speed, with optional speed ramp-up. |