Skip to main content

SwordTrail

A class in Root.Township, the global namespace.

Drives a TrailRenderer's width curve from how fast the object moves along chosen axes, so a weapon trail only shows on fast swings. Runs in edit mode too.

  • Listed in Global namespace: S
  • Inherits or implements MonoBehaviour
  • Attributes RequireComponent, ExecuteInEditMode

Constructors​

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

Fields​

6 private and internal fields
MemberWhat it is
private Vector3 axisSizeWeights per axis for how movement direction turns into width.
private List<Keyframe> keysThe width curve keyframes.
private Vector3 lastPositionPosition at the previous physics step.
private float minSpeedSquared distance per step below which the trail width is 0.
private int numberKeyFramesNumber of keys in the width curve.
private TrailRenderer trailThe TrailRenderer on this object.

Methods​

3 private and internal methods
MemberWhat it is
private void FixedUpdate()Pushes a new width from the movement since last step, or 0 if it moved less than minSpeed.
private void Start()Caches the trail and builds the starting width curve. Integer division makes all keyframe times 0.
private void UpdateList(float newValue)Shifts the width keys along by one, puts the new width first and applies the curve.