Manual

 

Introduction

The goal of Aerodynamic Movement is to simulate aerodynamic force without losing the ability to accurately set target points as the plugin does in standard projectile motion.

You can use this feature to simulate curve effect seen in sports such as football, baseball, golf (draw/fade), etc. You can also use it to simulate wind, air drag, or achieve creative weapon behaviors.

 

Core Concept

The core concept is the local offset vector, here we name it OffsetLocal. Definition: of an aerodynamic movement, the max displacement along local space, the local space is formed by projecting "end - start" onto xz plane as forward vector.

The figure below is a top-down view of a scene, it explains the definition and shows two example values of OffsetLocal. The underscore symbol _ indicates that the y axis value can be arbitrary.

AerodyCoreConcept

 

Standard Usage Process

Here we describe a standardized process of using the API.

A concrete example script following these steps can be found in the folder "Demos/Scripts/05 Aerodynamic Movement", named CurvyTest.cs. The corresponding example scene can be found in "Demos/05 Aerodynamic Movement.unity".

Preparation:

Let's prepare the script with some fields that can be adjusted in the Unity inspector panel. These are the fields used throughout the steps, but your own script can be different, for example, you may want to control the targetPoint via custom logic, so it can be a local variable instead of a private class field.

Step 0:

Create a new AerodynamicMoveSolver instance,

and optionally, add a custom callback that will be called when the projectile reaches target. Here we stop it and add a bounce to it:

If you also want to predict the trajectory, set up a PEBTrajectoryPredictor instance (here we call it predictor), the instance will be used later:

Note

Step 0 all happens in a Start() or Awake() method.

Step 1:

In this step, we calculate all the data needed by calling Solve(...). You can add the code below directly into your logic or encapsulate it to a method.

Here, we are using VelocityByHeight(...), but you can use any methods in Projectile class.

If you also predict the trajectory, call the predictor we added earlier.

Step 2:

This is the final step, we launch the projectile, and then set up execution of Aerodynamic Movement through AerodynamicMoveRuntime component. And now your projectile moves in the air in curve!

 

Scripting Reference

Aerodynamic Movement consists of 2 classes AerodynamicMoveSolver and AerodynamicMoveRuntime.

 

AerodynamicMoveSolver

 

OnFinished

Custom callback that will be called when the projectile reaches target. Note that it is triggered after a pre-calculated time, not by collision.

 

SolvedVelocity { get; }

The modified launch velocity that takes aerodynamic movement into account. The same value as the return value of Solve(...).

 

Acceleration { get; }

The continuous acceleration that is used to conduct aerodynamic movement.

 

OffsetVector { get; }

The world space version of offsetLocal (here, offsetLocal refers specifically to the value passed to Solve(...)). It is used internally to get offset end point ( = end + OffsetVector).

 

TimeOfFilght { get; }

The duration needed for the projectile to move to end point, the acceleration of aerodynamic move is applied during this period of time.

 

Solve(...)

Computes the values required for aerodynamic movement.

start: The launch point.

end: The target point.

offsetLocal: Of a aerodynamic movement, the max displacement along local space, the local space is formed by projecting "end - start" onto xz plane as forward vector.

v: The original launch velocity that makes the projectile move from start point to end point without taking aerodynamic move into account.

returns: The modified launch velocity that takes aerodynamic move into account.

 

ApplyAcceleration(...)

Executes the aerodynamic movement.

This is used internally in PEBTrajectoryPredictor class for aerodynamic movement prediction, but for the execution applied to real projectile, we recommend using methods in AerodynamicMoveRuntime class.

rBody: The Rigidbody of the object to which the acceleration is applied.

timer: This is used as a runtime context, it records how much time has been passed since the projectile launch.

returns: Whether or not the acceleration is applied. False means the procedure is finished.

 

AerodynamicMoveRuntime

 

TimeOfFlight { get; }

The duration needed for the projectile to move to end point, the acceleration of aerodynamic move is applied during this period of time.

 

Timer { get; }

How much time has been passed since the projectile launch.

 

AcquireRuntimeParameters(...)

Acquires the values from the AerodynamicMoveSolver instance called solver. A valid instance should have been called Solve(...) beforehand.

solver: The AerodynamicMoveSolver instance to acquire values from.

rBody: The Rigidbody of the object to which the acceleration is applied.

 

Run()

Starts running the AerodynamicMoveRuntime.

 

Pause()

Pauses the AerodynamicMoveRuntime. Can be useful for implementing replay and handling collisions.

 

Stop()

Pauses the AerodynamicMoveRuntime and reset the internal timer, i.e., stop. Can be useful for implementing replay and handling collisions.