Monday, August 1, 2022
HomeGame DevelopmentUnity 2D Parabolic character motion between platforms shows sudden behaviour

Unity 2D Parabolic character motion between platforms shows sudden behaviour


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:

enter image description here

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.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments