I have tried making top down and isometric games before, and was never able to get a good looking jump animation. So today, I actually did math involving some easy calculus. Here it is:
jumping objects follow a parabolic path. Parabolas are described by Y=AX^2+BX+C. If Y = height in pixels and X = steps, then we know that at X = 0 steps, Y = 0 pixels becuase the jump is just started. Therefore, C = 0, so the above equation simplifies to Y=AX^2+BX.The acceleration due to gravity is the first derivite of the position equation over time. so d/dt(AX^2+BX) = 2AX+B.The time where the height of the jump is at it's maximum is also the time when the derivitive equals zero, so setting 2AX+B=0 and rearranging yields X=B/(2A). Since the maximum height occurs at the midpoint of the time, multipyling the above equation by two yeilds the total time of the jump. X=2(B/(2A))=B/A.Returning to the parabola, Y=AX^2+BX, and using the equation for time at max height, X=B/(2A), we can get Y=A(B/(2A))^2+B(B/(2A)), which simplifies to Y=B/(4A)+(B^2)/(2A).We know have two unkowns, A and B, and two equations, Y=B/(4A)+(B^2)/(2A) and X=B/A. You must know determine what you want the max height of the jump to be, and the total length of time for the jump. Remember, this is in steps, that will be important later.Substitute the max height for Y and the time for X. By rearrangement, Y=B/(4A)+(B^2)/(2A) becomes Y=(1/4)(B/A)+(B/2)(B/A). The B/A term is simply X, so just replace it with your choice for the time and get Y=(X/4)+(BX/2). This equation know has only one unknown, B. Rearrange to get B=2((Y/X)-(1/4)).Now you have B in terms of known values, so just plug in the values and solve for B. Rearrange the X=B/A to get A= B/X and plug in the known value for B to get A.Now A and B are both known, so just plug into the original Y=AX^2+BX equation.There you have it, your jump equation! Now it must be implemented into GML for your game.First, make some variables in the create event so that they can be used later, lets call the jump height Y JY and the jump step X JX. Make a switch too, call it Jumping. Make all three equal to zero.Now make an event to start the jump, most likely a press key type event. It should start by checking if Jumping = 0, so that you don't jump during a jump. Then if Jumping = 0, set Jumping to 1 and JX to 0.Now make a step event and add this code:if Jumping = 1{
JX += 1
JY = -'X'*(A*power((JX/'n'),2)-B*(JX/'n'))
if JX = 'X'*'n'{
Jumping = 0
JX = 0
}
}
it doesnt have to be that complex :P
Right, I tried using an absolute value function to get the jump to work, but it looked triangly, so I wanted a better one.
oh i get it
I didn't need to read that right after I woke up >.<