Computer Science Canada Adding initial horizontal motion into a jumping procedure |
Author: | Mayb123 [ Tue Nov 20, 2007 1:13 pm ] | ||
Post subject: | Adding initial horizontal motion into a jumping procedure | ||
i am trying to allow for horizontal running velocity to be incorporated into the jump procedure giving a trajectory with a slight 2-3 pixel restraint on how much you can affect the trajectory by holding down the a or d keys (wasd controls). for example's sake, i took out the variables that require external files and replaced the character with a dot. any help would be greatly appreciated. thanks
|
Author: | richcash [ Tue Nov 20, 2007 3:28 pm ] |
Post subject: | Re: Adding initial horizontal motion into a jumping procedure |
Well, it really depends on you game. Do you want it to be realistic, do you want it to be like mario, etc. Generally, the faster someone is moving before jumping the further horizontally they will go. This suggests you should divide the x velocity on ground right before the jump by some constant and use the quotient as the new x velocity in air. The velocity of the object in the air is not affected by ground friction, so you should disable that while in mid-flight. You may choose to add air resistance, but it will be VERY small so you can also ignore it. The rest is up to you and your game. When the character lands you probably want to set all velocities to 0 (unless the character is on skates, where he would keep going on ground). You may want the user to be able to affect the 'take-off'. To do this check if the user is pressing the appropriate direction at the 'instant' the jump key is pressed. If they are, then you add more to the x velocity in that direction. If they aren't (they let go and then press jump key, you may infer that they want to jump straight up, but will likely still have some x velocity). You may also want to make a forward jump not have as much y velocity as a straight-up jump, because the person is splitting their jump force to go both forward and up. In mario-like games the user can effect the velocity of the character while in mid-air. I don't think someone can do this in real life, but it still might be good for your game. There are a number of other things that you can put in as well (that make it more fun or more realistic). |