Trick Shot Line

TrickShotLine and TrickShotLine2D have the same funcitonlity just different simulation space: TrickShotLine renders a visual preview (using a LineRenderer) of the multi‐bounce trajectory computed by a sibling TrickShot component. It concatenates all sampled points from each BallisticPath in trickShot.prediction and feeds them to the LineRenderer. Designers can choose to run the prediction once at startup or continuously update it every frame.
Requirements
[RequireComponent(typeof(LineRenderer))][RequireComponent(typeof(TrickShot))]Ensure this GameObject has both aLineRenderer(for drawing the path) and aTrickShot(for computing the trajectory).
Public Fields
Run on Start
public bool runOnStart(default:true)If checked,
trickShot.Predict()is called once inStart()(before the first frame).Use this when you only need a static preview that doesn’t change after the scene begins.
Continuous Run
public bool continuousRun(default:true)If checked,
trickShot.Predict()is called everyLateUpdate(), and the line is updated each frame.Use this for real‐time previews (e.g., aiming UI that follows the cursor or moving launcher).
Typical Designer Workflow
Scene Setup
Create (or use) a launcher GameObject and attach:
TrickShot(configured with speed, bounces, etc.)TrickShotLine
Add a
LineRenderercomponent alongside. Configure its material and width so it’s clearly visible.
Inspector Configuration
runOnStart:true→ Preview is generated once when the scene starts. If your launcher and gravity are static at startup, leave this checked.false→ No prediction at start; you’ll callTrickShot.Predict()manually or letcontinuousRunhandle it.
continuousRun:true→ The line updates every frame. Good for dynamic aiming or moving launchers.false→ The line only appears once (ifrunOnStartistrue) or after you manually callTrickShot.Predict()in your script.
Runtime Behavior
If
runOnStart = true && continuousRun = false:At
Start(), the trajectory is computed once, and the line is drawn. It remains static thereafter.
If
continuousRun = true:Each
LateUpdate(),TrickShot.Predict()recomputesprediction(sampling new points based on current position, rotation, etc.).UpdateLine()then refreshes theLineRendererto reflect any changes (e.g., new aim direction).
Manual Triggering
If both fields are
false, no prediction occurs automatically. To draw the line:csharpCopyEditvar ts = GetComponent<TrickShot>(); ts.Predict(); GetComponent<TrickShotLine>().UpdateLine(); // though UpdateLine() is private, you can toggle continuousRun or call Predict + wait one frameThe simplest approach is to set
runOnStart = false, continuousRun = false, then callPredict()in your custom script and rely onLateUpdate()ofTrickShotLineduring the next frame to draw it.
Designer Tips & Gotchas
LineRenderer Setup
Ensure the
LineRenderer’s “Use World Space” is checked. This script sets it automatically, but double‐check the material, color gradient, and width curve to suit your scene.If the line appears too thin or invisible, increase the
startWidth/endWidthand assign a bright or unlit material.
Minimizing Garbage
UpdateLine()callstrajectory.ToArray()each frame, which allocates a new array. If you experience GC spikes, consider caching a larger buffer or switching to a pooled array approach. In most scenes, this is negligible.
Matching Prediction to Projectile
Make sure your
TrickShotparameters (speed, resolution, bounces, etc.) match your actual projectile’s behavior. The line will only be accurate if those values reflect the real‐time launch settings.
Performance Considerations
High sampling resolutions (small
resolutioninTrickShot) and many bounces can produce thousands of points. IfcontinuousRun = true, this can affect frame rate.If you only need a static preview, set
runOnStart = trueandcontinuousRun = falseto avoid recomputing unnecessarily.
Empty or Null Paths
If
trickShot.predictioncontains no valid paths (e.g.,Predict()was never called or the target is out of range),trajectory.Countwill be zero and the line will not draw.You can check in
TrickShotor your own script whetherpredictionis empty before displaying UI elements.
Last updated