I've been trying to solve this little bug in my code for a while now, but I can't seem to figure it out yet. When running my program the player entity correctly falls to the ground due to the gravitational pull, but if he walks off of the ground then he doesn't fall.

As far as I can tell, the two collision checking if-else statements or something regarding them is probably messing up. The game seems to think that the player is colliding with something and therefore won't allow it to fall anymore.

If someone cares to check out the code and see if you can figure out a possible solution, thanks.

I think that you need to separately check collisions. Check the y axis and x axis collisions separately from the movement code. The only reference I see to y is when you jump. The only time I see it for x is when you move.

Also, there is no code that alters the y value. I'll have to go digging around, but it seems like it'll always be 0.

If you look at your willcollide calls you're defining your rectangle incorrectly in both cases. The first two parameters are the corners of the rectangle. In this case? You're setting them as your delta not your position. So your always checking against your bottom left tile. And you'll never collide on the left edges. :3

I never use a library unless I either can't code what I need or it's necessary. Collision is simple, when I don't mess up a piece of code as UprightPath has shown me, so I don't use a library for it. =P

Also, just as a bit of extra advice: Your collision detection will likely act oddly at times the way it's written. If the player is less than the delta away from the object that's going to be collided with it's going to stop without hitting the object. By that, I mean that its DX will be set to 0 at such a point that its edge will not touch the other object. This will probably be more noticeable when the player is falling from a higher point (e.g. has a higher DX before impact) or if you increase the update time. It will have a sort of falling stutter: It'll have DX = 0 while above the ground, then have gravity applied until it's DX is greater than the distance between the player and floor, stop again, then continue. In the end, if the positional information were different then you might even see the player "float" above the ground due to this.

Hmm... Now that you mention it, I do think that it could do that. I'll rework things if I do come across that issue in the future, but at the moment I should be able to prevent it with carefully chosen values for the gravitational pull, movement speeds, etc...

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org