Hello man, and welcome!
Check out this post for detailed information:
viewtopic.php?f=4&t=8831&hilit=jump#p54562
Some tips you could find useful:
Depending on what you would like to accomplish, you typically do not want to modify the player's Y position inside a loop, and then execute that loop in more than one frame. The reason behind this is that you want, instead, to modify the player's vertical position throughout a number of fixed frames, loop-free, since each frame is actually modifying the previous vertical position - that is, the player increases (or decreases) his position on each frame.
To achieve a behavior like this, you must include the
dt (delta time) variable in your calculations. dt is a variable that quantifies the time elapsed between drawing and computing frames.
For instance:
Code: Select all
playerY = playerY + playerSpeed*dt
If placed inside an update block, executes every frame, increasing the variable “playerY” by playerSpeed * dt times. This increment depends on dt and a fixed “speed” variable, if you try initially a playerSpeed of 100, then, playerY will be increased by 100 every frame.
Some things to consider:
dt can be a tricky concept to understand, what you must be aware of is that it is
the temporal variable that you must include in computations that somewhat must “know” the time elapsed between one (frame) event and another.
dt is defined as the inverse of the frame rate, and varies depending on the hardware where the code is being executed. This could lead to nasty bugs, where your player moves faster or slower, depending on the host computer. To avoid this, set a constant frame rate (eg. 60) inside your program.
Hope it helps!