0

I am trying to write an enemy AI that jumps between available platforms when it doesn't have ground below its feet. I want the character to do the jumps in a parabolic fashion rather than doing a straight jump between them as shown in the image below:

enter image description here

And to do the arc motion, I use this function and set the actor's velocity to the value 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));

}

However my function doesn't seem to perform properly. If the target is higher than start position the target just does a straight jump to the target rather than a parabolic one, and sometimes it gets too much X velocity. How can I achieve the parabolic jumps that I'm trying to achieve? Thanks in advance.

0 Answers0