I have searched for this question but was unable to turn up any results - I am making a Java platform game (I have created many top-down games, but nothing with gravity like a platformer) and I have implemented terminalVelocity, etc. My problem is that, say when the player is falling at a rate of 8 pixels I check collision for the player 8 pixels ahead before it moves, and if there is a collision the player does not move - but, say that there are 4 pixels until a block but the player is moving at 8 pixels, the collision detection stops the player because 8 pixels ahead there is a block, but the player hovers because there is a 4 pixel gap. How would the player fall those extra 4 pixels?
Take the 2-minute tour
×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.
Well what I do for my 2D game is that inside of checking before the players moves, I deal with collision after the player moves. Before I used to run into problems like yours because of the fact that when you check before hand, you stop the player from moving. Heres what you have to do, lets say that there is a block at some x, y, width and height ........o.......//o is the player ................ ................ ................ .......[].......//The block We'll keep making the player fall and after we do so we check if it is inside of a block
if the player is inside of the block, we'll push it upwards
Now it's right onto of the block and no gap :D Am currently making a platform - sandbox game with java for android and this is how I deal with the collision if you like my answer please mark it as the accepted answer and +rep |
|||||||||||||
|