Sign in to follow this  

jumping using physics

This topic is 3595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok basically ive spent the last day working on a jumping system: *on collision of "floor" and "player" material types the players flag is set to being on the ground, then set every frame in the players update to false in order to force it to update every frame. *when user presses jump, impulse of "variable" amount is added in the up direction to the player * the players movement is handled by forces. every frame the "desired" force is set to 0,0,0 then if keys are down appropriate forces are set in the direction. this way when the force is calculated it will apply the appropriate forces in the opposite directionsin order to stop the player without using friction. now when i jump obviously it goes upwards, but can still move / run forwards whilst in the air, easy enough to disable this but then i have the problem of how to correctly move forwards as you would do if you was jumping onto say a platform or something, is possibly a couple of obvious solutions that wouldnt be so elequent, but would like to see what other peoples solutions are thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Stowelly
now when i jump obviously it goes upwards, but can still move / run forwards whilst in the air, easy enough to disable this but then i have the problem of how to correctly move forwards as you would do if you was jumping onto say a platform or something


This is handled automatically. If you have forwards velocity at the moment you leave the ground, you will continue to have forwards velocity while you are in the air, because there is no force pushing you backwards (only down).

Share this post


Link to post
Share on other sites
Quote:

now when i jump obviously it goes upwards, but can still move / run forwards whilst in the air, easy enough to disable this but then i have the problem of how to correctly move forwards as you would do if you was jumping onto say a platform or something, is possibly a couple of obvious solutions that wouldnt be so elequent, but would like to see what other peoples solutions are


If you do not want the player to be able to move while in the air, then you could do something as simple as creating a playerInAir flag, and when the player presses jump, the flag gets set to true. Then, when you read in keyboard input, add in a guard to check if the playerInAir flag is false, and if so, read keyboard input. For example

boolean playerInAir = false;

if(spacePressed && !playerInAir) player.jump(); playerInAir = true;
if(leftPressed && !playerInAir) player.move(LEFT);
...


Although, you may want the player to be able to control the character while in air. In that case, you could just check the playerInAir flag when a call to move() is made, and if playerInAir is true, do something simple like divide the amount that determines how far the character moves by 2, or some other simple division.

This is something simple that comes to mind first, there are plenty of ways to achieve what you want.

Share this post


Link to post
Share on other sites
thanks alot, ive solved it quite easily by only applying the stopping force when the "onGround" flag is set to true, should have spent more time thinking it through logically, thanks alot

Share this post


Link to post
Share on other sites

This topic is 3595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this