falling through the ground

BlitzPlus Forums/BlitzPlus Programming/falling through the ground

pyro821(Posted 2004) [#1]
Here is what im trying to do is have a player be able to jump and land on top of the ground. But he jumps up and goes about half way through the ground and then goes on top of the ground. I know why this is happening but i can not think of something that will make it work the way i want it to. Here is how it works.

if your on top of the ground and you push shift a veriable is turned to 1 call jump (jump = 1). So if jump = 1 then y = y - gravity and gravity equals 15. at the same time gravity is geting subtracted by 1 (gravity = gravity - 1). So what happens is the first frame the player will go up 15pix then 14pix then 13pix ect untill it gets to -1 and it starts to go down -1pix, -2pix, -3pix. when it hit the ground jump = 0 and the jumping ends. But here is the problem when it hits the ground I what it to stop right on top of the ground but it goes about half way through then comes up on top of the ground. If some one can help that would be great.


Kevin_(Posted 2004) [#2]
ahhh! OK, here is one way. Perform your collision check before you actually move your player. In other words, try and predict the next x & y coordinates of your player before you actually move him. If your player + the next gravity value would position your player below the ground then let the y of your player = the ground y (- height of your image).

Hope that helps.


Grey Alien(Posted 2004) [#3]
I concur