I’m attempting to put in writing an enemy AI that jumps between accessible platforms when it would not have floor beneath its toes. I need the character to do the jumps in a parabolic style moderately than doing a straight bounce between them as proven within the picture beneath:
And to do the arc movement, I take advantage of this perform and set the actor’s velocity to the worth returned:
public static Vector2 GetVelocityForArc(Vector3 arcStartPos, Vector3 arcTargetPos, float objectGravityScale, float arrivalTimeVal) {
float velocityX = (arcTargetPos.x - arcStartPos.x) / arrivalTimeVal;
float velocityY = (float)((arcTargetPos.y - arcStartPos.y - 0.5 * (Physics.gravity.y *
objectGravityScale) * Mathf.Pow(arrivalTimeVal, 2)) / arrivalTimeVal);
return new Vector2(velocityX, Mathf.Abs(velocityY));
}
Nonetheless my perform would not appear to carry out correctly. If the goal is larger than begin place the goal simply does a straight bounce to the goal moderately than a parabolic one, and typically it will get an excessive amount of X velocity. How can I obtain the parabolic jumps that I am attempting to realize? Thanks prematurely.