three issues regarding collisions in a simple platformer.
by James Peter Fayette · in Torque Game Builder · 01/30/2013 (1:10 pm) · 4 replies
I am creating a simple platformer game for practice, and I have found three issues with the handling of collisions with the ground. The game is loosely based off of the platformer tutorial in the engine documentation, with a number of significant differences, such as replacing the tutorial's rubbish ground detection system with a scene object mounted to the player's feet.
The first issue is that, when the player object lands on the edge of a platform, it immediately falls off, slipping down the ground, despite the fact that you can easily stand in such a position if you just walk there.
This is made more troubling by the second issue, which is likely related. when the player lands on the border between two tiles in my platforms tilemap, it only seems to register the collision with one of the tiles, so issue one causes the player to fall through the ground., causing the game to crash after a bit.
the third issue is a small one, but it annoys me, so I'm going to ask. whenever the player lands on a surface after jumping, it falls about halfway in to the ground for a split second before coming to rest on top of the surface.
I hesitate to post this in the bugs subforum, because it is likely my own fault. a zip file of the project folder can be found here if it will help.
The first issue is that, when the player object lands on the edge of a platform, it immediately falls off, slipping down the ground, despite the fact that you can easily stand in such a position if you just walk there.
This is made more troubling by the second issue, which is likely related. when the player lands on the border between two tiles in my platforms tilemap, it only seems to register the collision with one of the tiles, so issue one causes the player to fall through the ground., causing the game to crash after a bit.
the third issue is a small one, but it annoys me, so I'm going to ask. whenever the player lands on a surface after jumping, it falls about halfway in to the ground for a split second before coming to rest on top of the surface.
I hesitate to post this in the bugs subforum, because it is likely my own fault. a zip file of the project folder can be found here if it will help.
About the author
#2
02/01/2013 (11:55 am)
thanks for the advice. my camera does lag behind a bit in the later iterations. however, it would appear that disabling gravity whilst the player is on the ground eliminates all three problems, for whatever reason.
#3
For 1 and 2, what collision polygon are you using? Mine kind of looks like a square with a triangle on top and bottom (can't remember where I got that but thought it was in the tutorial...). With that collision polygon, catching an edge will bounce the character to the side and the point at the bottom also can't touch more than one square.
For 3, I'm using cast collision to look at least a frame (or more) ahead. Then if collision will occur I "rubber band" the character to the point of collision. For future I will likely rework this code to adjust the falling velocity to have the character just above the target at the next frame and then rubber band them the short distance to impact.
Not sure if this will actually fix your problem but mine is running pretty good right now for a prototype anyway.
02/04/2013 (7:34 am)
I've been working with this as well and have a couple possible thoughts.For 1 and 2, what collision polygon are you using? Mine kind of looks like a square with a triangle on top and bottom (can't remember where I got that but thought it was in the tutorial...). With that collision polygon, catching an edge will bounce the character to the side and the point at the bottom also can't touch more than one square.
For 3, I'm using cast collision to look at least a frame (or more) ahead. Then if collision will occur I "rubber band" the character to the point of collision. For future I will likely rework this code to adjust the falling velocity to have the character just above the target at the next frame and then rubber band them the short distance to impact.
Not sure if this will actually fix your problem but mine is running pretty good right now for a prototype anyway.
#4
02/04/2013 (10:22 am)
thanks for the advice, but the problem has been resolved by the removal of gravity when the player is on the ground.
Torque Owner Alpha-Kand
Hunter's Meadow
Here are some suggestions you could try:
1: Have your player constantly get the id of the last floor it touches. Then have the player compare itself and the floor's x positions to see if the character should be standing over nothing. If so activate falling again and have your player forget the id.
2. Your second problem MIGHT disappear if you implement the above properly.
3.There isn't a whole lot you can do about the sinking into the floor except trust the engine to handle falling on the ground, maybe have the camera lag behind the character the SLIGHTEST so it keeps up but is not rock solid rigid and perhaps make sure you have an animated player to hide any remaining jerkiness.
Good luck. Making a platformer isn't easy.