Trick Shot Constant Acceleration

Trick Shot Constant Accelation has a 2D variant for use with Trick Shot 2D: TrickShotConstantAcceleration dynamically composes a 3D “gravity” (or any constant force) vector each frame by summing:
World‐space forces (e.g., gravity).
Local‐space forces (rotated by the GameObject’s current orientation).
It then assigns that combined acceleration to a sibling TrickShot component, ensuring your projectile always uses the correct constant acceleration—even if the launcher rotates or moves at runtime.
Requirements
This GameObject must have a
TrickShotcomponent (enforced by[RequireComponent(typeof(TrickShot))]).
Public Fields
Global Constants
public List<Vector3> globalConstantsForces expressed in world‐space (e.g.,
(0, –9.81f, 0)for earth‐gravity).Defaults to one entry:
(0, –9.81f, 0).Designers can add multiple entries here to combine several global forces (e.g., wind, custom gravity).
Local Constants
public List<Vector3> localConstantsForces expressed in local‐space, relative to this GameObject’s transform.
Each entry is transformed by
transform.rotationbefore being added.Use this to apply forces that should follow the launcher’s orientation (e.g., a “downward” pull relative to a rotating turret).
Usage Example
Scene Setup
Attach both
TrickShotandTrickShotConstantAccelerationto your launcher GameObject.
Inspector Configuration
globalConstantsBy default,
(0, –9.81f, 0)is present.To simulate a horizontal wind, add
(2f, 0, 0).
localConstantsTo apply a downward pull relative to the turret—even if it tilts—add
(0, –9.81f, 0)here.
At Runtime
Every frame,
TrickShotConstantAccelerationcalculates the sum of all listed vectors and writes it toTrickShot.constantAcceleration.Your
TrickShot.Predict()orShoot()methods will then use this combined acceleration automatically.
Designer Tips
Multiple Forces
Combine wind, gravity, or any other constant fields by adding them to
globalConstants.For example,
(0, –9.81f, 0)+(1f, 0, 0)applies both gravity and a constant rightward push.
Local vs. Global
Use
localConstantswhen the force should rotate with your GameObject (e.g., pulling “down” toward the launcher’s “bottom” even if it’s angled).Forces in
localConstantsare transformed bytransform.rotationeachLateUpdate.
Overriding Static Values
Any
constantAccelerationvalue set directly on theTrickShotcomponent will be overridden inLateUpdate.If you need a fixed acceleration regardless of these lists, disable or remove this component.
Dynamic Adjustments
You can modify either list at runtime via script to change gravity or wind on the fly. Example:
csharpCopyEditvar accelHelper = GetComponent<TrickShotConstantAcceleration>(); accelHelper.globalConstants.Add(new Vector3(0, 5f, 0)); // temporary upward thrust
Last updated