Reputation: 586
More specifically, I want to place Coin
s in such a pattern that the player can collect all coins in one jump. I drew a little picture in paint (yellow circles = coins) to demonstrate what I mean:
Is there any sort of 'trick' I can use? I found the equations I need but they all require time of flight (time is not used in my jumping method at all)
Upvotes: 1
Views: 140
Reputation: 24454
To compute the exact trajectory of your jumping player character, you need simple physics. I don't know exactly what start parameters you have, but most probably you know the horizontal and vertical velocity (speed) of your player when it jumps off and the amount of "gravity" as vertical acceleration:
Horizontal velocity: vx [pixels per second]
Vertical veloctiy: vy [pixels per second]
Gravity: a [pixels per second^2]
The player's position changes over time and can be defined by the two functions x(t)
and y(t)
. As we only want to look at the jumping movement, we set t
to be zero at the start of the jump.
Luckily, the two functions are completely independent. The horizontal movement is linear:
x(t) = vx*t
The vertical movement is more complex as it is influenced by gravity:
y(t) = vy*t - (a/2)*t^2 = t*(vy - t*a/2)
Almost done. The only thing we need to determine is the time-range of the jump. So the question is: When does the player land on the floor again? Or in other words: When is y(t)
zero?
It is easy to see that y(t)
has two roots: t1 = 0
and t2 = 2*vy/a
.
So the time-range of the jump is [0, 2*vy/a]
.
Upvotes: 1