Last active
July 21, 2022 15:09
-
-
Save onewinter/fef4a45e2415197715854d87c594c10b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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