Home Game Development unity – Adding Velocity To Movement In A Parabolic Arc

unity – Adding Velocity To Movement In A Parabolic Arc

0
unity – Adding Velocity To Movement In A Parabolic Arc

[ad_1]

Good Evening All,

I’m transferring my projectiles in a parabolic arc utilizing the next code:

(Credit to Joe Strout for the formulation! https://luminaryapps.com/weblog/arcing-projectiles-in-unity/)

public IEnumerator BounceInAnArc()
{

    Vector3 startPos = GameEngine.Instance.BattleManager.TurnHero.remodel.place;
    Vector3 targetPos = GameEngine.Instance.BattleManager.TargetEnemy.remodel.place;
    float jumpSpeed = 3;
    float arcHeight = 3;
    Vector3 nextPos = Vector3.zero;


    

    whereas (remodel.place != targetPos)
    {
        
        // Compute the following place, with arc added in
        float x0 = startPos.x;
        float x1 = targetPos.x;
        float dist = x1 - x0;

        

        float nextX = Mathf.TransferTowards(remodel.place.x, x1, (jumpSpeed) * Time.deltaTime);
        float baseY = Mathf.Lerp(startPos.y, targetPos.y, (nextX - x0) / dist);
        float arc = arcHeight * (nextX - x0) * (nextX - x1) / (-0.25f * dist * dist);
        nextPos = new Vector3(nextX, baseY + arc, remodel.place.z);

        remodel.place = nextPos;
        
        yield return null;
    }


}

This works nice, however the pace is constant all through the objects complete motion.
Now, I wish to add weight/velocity to the item’s vertical motion on the Y axis.
I would really like the projectile begin quick and start decelerating it is Y velocity because it travels up within the Y axis. I’d prefer it to slowly taper it is velocity to 0 when it reaches it is peak peak. Then, I would really like it to start out accelerating because it falls down in the direction of it is goal.

Is anybody capable of help me with how I can accomplish this? Thanks for taking the time!

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here