2d Platformer Horizontal Max Speed

I am currently using GetComponent ().velocity = leftforce ; as my code but the character fall super slow but the problem with addforce right now is they start to go to fast and I’m not sure how to sure to add a maximum speed to add force.

multiply the code x Time.deltaTime in the horizantal axis and set the speed in the inspector. by

One possible approach is to scale your input relative to your current speed. For example, if you’re currently moving at your maximum speed, the force added will be scaled down to 0. This generally also takes a little tweaking to ensure that you’re not preventing movement in the opposite direction.

Note: The code’s untested, imperfect, and technically built for a 3D environment, but hopefully it may help to give some ideas of how to approach movement speed scaling.

// C#

public float acceleration; // How fast do you want to reach max speed?
public float maxSpeed; // The maximum speed you wish to reach. Either don't let it be zero or put in an if statement to avoid division by 0
Rigidbody rb; // Defined earlier for quicker access

// ...

Vector3 movementInput = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);

// ...

float speedScale = Vector3.Dot(rb.velocity / maxSpeed, movementInput);
speedScale = 1.0f - (Mathf.Clamp01(speedScale));

rb.AddForce(movementInput * acceleration * speedScale);