platformer maintaining horizontal speed until landing.

Rojax

Member
Good day,
So I am very very new to this scene and I am trying to create a basic platformer with punishing falls similar to a getting over it style game. I have basic character movement and dynamic jumping down however I do not understand how I can maintain my speed while in the air from jumping. it just doesnt feel good being able to let go of a direction key and stopping mid air. I want to be able to continue through the air in a sort of arc like a natural jump and I cant for the life of me figure out how to do this and im sure it is very simple. Any help for guidance would be greatly appreciated as I am still learning and would like to understand how to accomplish this. The current code I have below is just moving left and right and the dynamic jump. Again thank you for any knowledge you share.
1619375346503.png
 

Simon Gust

Member
You can hide your hsp calcuation behind an "on the ground" check, then you would have no control in the air at all (if that is what you want).
 

4i4in

Member
You can storage Your initial horizontal component on enother entry and use it to calculate fake momentum and disable movement when this component is not 0. Let say ground/colision give instant frictiot that nullyfi this component.
 

Rojax

Member
You can hide your hsp calcuation behind an "on the ground" check, then you would have no control in the air at all (if that is what you want).
Im not sure how that translates into my code sorry, i really dont understand a whole bunch when it comes to coding just yet.
 

MaxLos

Member
it just doesnt feel good being able to let go of a direction key and stopping mid air.
You need to adjust what you currently have to work with momentum (accel and friciton).
Code:
// calc movement
var move = right - left;
hsp = move * walksp
^ Right now, you have it set up so the player instantly moves at their walk speed if the left or right key is held, and instantly stops moving if none or both are held. Adding momentum is pretty simple, there's plenty of tutorials online for it
 

Rojax

Member
You need to adjust what you currently have to work with momentum (accel and friciton).
Code:
// calc movement
var move = right - left;
hsp = move * walksp
^ Right now, you have it set up so the player instantly moves at their walk speed if the left or right key is held, and instantly stops moving if none or both are held. Adding momentum is pretty simple, there's plenty of tutorials online for it
Okay I understand a bit better, ill see what resources I can find. Thanks for the help.
 

Bentley

Member
I do not understand how I can maintain my speed while in the air from jumping. it just doesnt feel good being able to let go of a direction key and stopping mid air. I want to be able to continue through the air in a sort of arc like a natural jump
Atm, if you release the key, your hsp becomes 0. Instead, decrease hsp each step in the step event:
GML:
if (hsp > 0) hsp = max(0, hsp - 0.2);
else if (hsp < 0) hsp = min(0, hsp + 0.2);
You can make a variable called "fric" and set it to something in the create event. Then swap that in for 0.2 (or whatever you have).
 
Top