PlatformerController2D icon indicating copy to clipboard operation
PlatformerController2D copied to clipboard

Acceleration?

Open elvisish opened this issue 1 year ago • 4 comments

Is it possible to add acceleration to the controller? Friction works well for getting the correct deceleration when adjusted with max acceleration, but there's no way to separately control the acceleration speed for fine tuning. What would be the best way of adding it to the controller?

elvisish avatar Jan 08 '25 21:01 elvisish

Currently, you can change the acceleration, but the acceleration and deceleration will always be the same. If I understand correctly, you want the acceleration and deceleration of the controller to be different?

One way to add this would be to make the friction change depending on whether or not you are holding left or right. For example, if you want the controller to accelerate faster than it decelerates, you could make the friction 5 when the player is not holding left or right, and 20 when they are holding left or right. In this case, your acceleration will be fairly quick, but as soon as you release the move key, you will decelerate slowly as if you are on ice.

Ev01 avatar Jan 20 '25 06:01 Ev01

Currently, you can change the acceleration, but the acceleration and deceleration will always be the same. If I understand correctly, you want the acceleration and deceleration of the controller to be different?

One way to add this would be to make the friction change depending on whether or not you are holding left or right. For example, if you want the controller to accelerate faster than it decelerates, you could make the friction 5 when the player is not holding left or right, and 20 when they are holding left or right. In this case, your acceleration will be fairly quick, but as soon as you release the move key, you will decelerate slowly as if you are on ice.

Thanks, I'll try that, might take a bit of changing things around but that seems like the easiest approach!

elvisish avatar Jan 20 '25 08:01 elvisish

Okay, good luck and don't hesitate to ask for help if you get stuck! I implemented variable jump height in a similar way (by changing gravity depending on whether or not you are holding the jump key), so if you don't know where to start you could look at the apply_gravity_multipliers_to function for inspiration.

Ev01 avatar Jan 20 '25 11:01 Ev01

Okay, good luck and don't hesitate to ask for help if you get stuck! I implemented variable jump height in a similar way (by changing gravity depending on whether or not you are holding the jump key), so if you don't know where to start you could look at the apply_gravity_multipliers_to function for inspiration.

Thanks, I'll check that out!

elvisish avatar Jan 23 '25 13:01 elvisish