Jumping problem
by Levi Walton · in Torque Game Builder · 08/28/2006 (8:09 pm) · 2 replies
Im having trouble with getting a character to jump. it will jump if its in the air, but if it lands on a platform it will not jump. it will still move but wont jump. ive looked at the platform tutorial on tdn but it didnt seem to help me. maybe i just didnt understand it completely. does anyone know if there is another tutorial dealing with platormers? thanks for any help you can give.
#2
so I will try to implement your idea on my player and check if the enemy collide with my player my player ill die but if the enemy collide with the rectangle arround my player feet the enemy will die.
I will try it tomorrow or after tomorrow and I will tell you the result.
08/30/2006 (7:57 am)
Thomas your idea is greate I will try it on my code where I wont my player (like Mario) if he jump on the head of the enemy the enemy will die.so I will try to implement your idea on my player and check if the enemy collide with my player my player ill die but if the enemy collide with the rectangle arround my player feet the enemy will die.
I will try it tomorrow or after tomorrow and I will tell you the result.
Torque Owner Thomas Buscaglia
You obviously want the player to be able to jump only when on a surface he should be able to jump off of. One way to get this to happen is to have a field on the player that stores whether they are on the ground or not then create some function to determine whether or not that's the case and set the field accordingly. With that information stored on the player, when the player presses the jump key/button we can just check the field to see if the player is on the ground and if they are then we initiate a jump.
The tricky part here is deciding whether or not the player is actually on the ground, which is where I think your problem might be. When working on the platformer template we went through about four or five different methods before we decided on one we liked. I don't have the code in front of me, but I think what we finally settled on was a pickRect based on the bounding box of the player's collision polygon, the local coordinates of which we cached on the player during the onLevelLoaded callback. The rectangle used is slightly thinner than the width of the player's collision poly and stretches from just above its feet to just below its feet. We iterate through the set of objects returned from the pick and check if they are "ground" objects. To speed up the process, we set the group mask of the pick to ignore everything but our platform group.
I know that might all seem overly complicated, but it was the most reliable way we were able to come up with. Hopefully this helped you out.