Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@onewinter
Last active July 21, 2022 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onewinter/fef4a45e2415197715854d87c594c10b to your computer and use it in GitHub Desktop.
Save onewinter/fef4a45e2415197715854d87c594c10b to your computer and use it in GitHub Desktop.
[SerializeField] private AnimationCurve curveHeight;
[SerializeField] private float curveMaxHeight;
public Vector3 Move(Projectile projectile)
{
// move towards the target in an arc, taking a constant amount of time
var linearT = projectile.CurrentTime / Duration;
// we have to move XZ and Y separately so they dont fight each other
var movePosition = Vector3.Lerp(projectile.StartPosition.PositionXZ(), projectile.TargetPosition.PositionXZ(), linearT);
// in case the start and end Y values are different (which they should be since the turret is higher)
var baseY = Mathf.Lerp(projectile.StartPosition.y, projectile.TargetPosition.y, linearT);
// use the animation curve (upside down parabola) to find the magnitude of the Y change
var arc = curveMaxHeight * curveHeight.Evaluate(linearT);
// finally, add it all together
movePosition.y = baseY + arc;
return movePosition;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment