Wednesday, September 28, 2022
HomeGame Developmentunity - Including Velocity To Motion In A Parabolic Arc

unity – Including Velocity To Motion In A Parabolic Arc


Good Night All,

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

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

public IEnumerator JumpInAnArc()
{

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


    

    whereas (rework.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.MoveTowards(rework.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, rework.place.z);

        rework.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 love the projectile begin quick and start decelerating it is Y velocity because it travels up within the Y axis. I would prefer it to slowly taper it is velocity to 0 when it reaches it is peak peak. Then, I would love it to start out accelerating because it falls down in the direction of it is goal.

Is anybody in a position to help me with how I can accomplish this? Thanks for taking the time!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments