0
\$\begingroup\$

I want to make a game similar to "Dancing HOP: Tiles Ball EDM Rush"

Animated gif showing how the game is played

I am trying to make an object jump from point a(z=0) to b(z=10) to c(z=20) and so on, keeping the z axis distance constant for each hop.

I also want to change the x axis value when the player swipes on the screen. While swiping it should move from eg. (x=0) to (x=2 or x=-2). This translation on the x axis should be in a curve, while the object keeps moving in the z axis undisturbed.

Here is the code I have so far:

IEnumerator FollowArc(Transform mover, Vector3 start, Vector3 end, float radius, float duration) { 

    //print(start);
    //print(end);
    Vector3 difference = end - start;
    float span = difference.magnitude;

    // Override the radius if it's too small to bridge the points.
    float absRadius = Mathf.Abs(radius);
    if (span > 2f * absRadius) radius = absRadius = span / 2f;

    Vector3 perpendicular = new Vector3(difference.y, -transform.position.x, difference.z) / span;
    perpendicular *= Mathf.Sign(radius) * Mathf.Sqrt(radius * radius - span * span / 4f);

    Vector3 center = start + difference / 2f + perpendicular; Vector3 toStart = start - center;

    float startAngle = Mathf.Atan2(toStart.y, toStart.x); Vector3 toEnd = end - center;

    float endAngle = Mathf.Atan2(toEnd.y, toEnd.x);

    // Choose the smaller of two angles separating the start & end
    float travel = (endAngle - startAngle + 5f * Mathf.PI) % (2f * Mathf.PI) - Mathf.PI;

    float progress = 0f;
    if (movingSignCheck == 0) { 
        travel = -travel;
    } else if (movingSignCheck == 1) { 
        travel = -(-travel);
    }

    do { 
        float angle = startAngle + progress * travel;
        mover.position = center + new Vector3(Mathf.Cos(angle), Mathf.Sin(angle)) * absRadius; 
        progress += Time.deltaTime / duration;

        yield return null;
    } while (progress < 1f);

    mover.position = end; 
}
\$\endgroup\$
5
  • \$\begingroup\$ We have lots of existing Q&A about calculating parabolic trajectories under the projectile-physics tag. Can you show us how you've tried to implement this feature based on the research you've done so far? \$\endgroup\$ – DMGregory Dec 16 '19 at 14:23
  • \$\begingroup\$ Here is my script please have a look [drive.google.com/open?id=18URlip_uAiP5mtXScyWw1xy-Mmc1Iglv] @DMGregory here is the code i am using to do this but the jump is not on the same distance difference in z axis \$\endgroup\$ – next age Dec 17 '19 at 5:50
  • 1
    \$\begingroup\$ I won't click on external links, but you're welcome to edit your question to include the relevant detail embedded in the question itself. \$\endgroup\$ – DMGregory Dec 17 '19 at 12:16
  • \$\begingroup\$ I've taken the liberty of editing your code and example into your question as I asked you to do previously. It looks like the code you're using is from an answer I wrote last year, which is for circular arcs, not parabolic arcs as described in your question title. Can you clarify, is it circles or parabolas you want? Where have you run into trouble implementing your desired curve? \$\endgroup\$ – DMGregory Dec 18 '19 at 17:52
  • \$\begingroup\$ Thank you so much for your cooperation ,and please recommend me either i should use parabolic or circular arcs for forward jumping , i request you to look at the video of game link please , i have tried this code in moves my object in circular left to right and right to left and i want keep moving in z axis as well with circular arc on fixed positions like 0 to 10 to 20 to 30 and so on. @DMGregory \$\endgroup\$ – next age Dec 19 '19 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.