2
\$\begingroup\$

I have an object that can jump.

When it jumps, its Y velocity becomes -600 (pixels/second).

For up to .2 seconds, it can ignore gravity.

After .2 seconds, it begins to accelerate downward at 2100 (pixels/second).

Independently from its Y velocity, the object can move on the X axis up to 220 (pixels/second) or -220 (pixels/second).

How do I calculate whether or not, with a given starting x/y coordinates it can jump to a target x/y coordinate?

Also, how do I calculate the necessary X velocity to reach its target in the proper amount of time so that it doesn't overshoot or undershoot?

\$\endgroup\$
4
  • \$\begingroup\$ Why is the speed to the left different from the speed to the right? \$\endgroup\$
    – Peethor
    Commented Dec 28, 2015 at 6:25
  • \$\begingroup\$ Also, I assume the downward acceleration is 2100 pixels per second per second? \$\endgroup\$
    – Peethor
    Commented Dec 28, 2015 at 7:20
  • \$\begingroup\$ have a look at this link \$\endgroup\$ Commented Dec 28, 2015 at 9:41
  • \$\begingroup\$ @Peethor Sorry, the discrepency between left and right movements was a typo, I corrected it. And yes, the downward acceleration is 2100 px/per second^2 \$\endgroup\$ Commented Dec 29, 2015 at 0:45

2 Answers 2

6
\$\begingroup\$

You can find both at the same time:

  • Pre-calculate a jump curve at maximum X velocity (blue curve)
  • intersect the approximated curve on the downward side where the target platform height is the same (red dotted line)
  • if the platform is further than this you can't make the jump
  • scale down the curve on the X axis to match the X of the target (cyan arrow)
  • that scaling applied to max X velocity gives you the needed X velocity to reach the platform in a nice arc.

enter image description here

If you want different possible jump heights you can calculate a few different curves and pick the best one.

You may want to add another step to check for collisions, eliminating from the list of possible trajectories.

The jump curves don't need to be calculated every time, you can generate them once when the game starts.

This applies to 3D just as easily.

Can be extended to handle double-jumps and other variations.

If X speed varies during the jump it'll require a bit of adjustment but given enough of a margin it might not matter.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you so much for your answer, although I'm trying to find a way to express this algebraically because I'm trying to use this for AI to calculate whether or not a jump is possible, and then at what Xvelocity they will have to jump to reach desired platforms. \$\endgroup\$ Commented Dec 30, 2015 at 2:36
1
\$\begingroup\$

You can calculate limits of your movement with these two formulas:

Maximum Altitude (Ymax) = (Initial Y velocity)^2 / 2*(gravity)

Maximum Reach (Xmax) = (Initial X velocity) * 2 * (Initial Y velocity) / (gravity)

\$\endgroup\$
4
  • \$\begingroup\$ Just to be pedantic, it doesn't accelerate upward when it ignores gravity. Because what I'm stating by that, specifically, is that for up to 0.2 seconds there is no acceleration, or change in velocity. The initial acceleration is the jump itself, the acceleration would be the active force on gravity on the jumping object, causing alteration to its velocity. \$\endgroup\$ Commented Dec 30, 2015 at 2:26
  • \$\begingroup\$ Force applies acceleration to an object. When the object jumps (as described in the OP), no force is applied to it upwards. Rather, its upward velocity is immediately modified to a value. Assuming no other forces are present, no gravity means no downward acceleration for the initial .2 seconds of the jump. This means the velocity is constant, as the velocity of any object would be in a forceless vacuum (as opposed to accelerating in any direction, like you said). \$\endgroup\$ Commented Oct 10, 2018 at 13:26
  • \$\begingroup\$ @S.TarıkÇetin, you are probably confusing velocity with acceleration. There is a constant velocity upwards with no gravity (assuming an upwards initial velocity), but no constant acceleration. No forces = no acceleration. \$\endgroup\$ Commented Oct 10, 2018 at 13:28
  • \$\begingroup\$ Yes, I appear to have misinformed people. I edited my answer and removed the incorrect comment. My apologies about the inconvenience. \$\endgroup\$ Commented Oct 10, 2018 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .