Adding acceleration to players

I am making a sports game and players can have different stats like speed and acceleration. Not really sure how I would add acceleration I was thinking of like tweening the walkspeed from 0 to 16 but then how would I fire it, is there a way to make something fire everytime a player starts moving?

1 Like

Just use UserInputService or ContextActionService.

UIS is easier because you could just check for an inputted W, A, S, or D. You can have this running asynchronously to the main script with a coroutine or whatever floats your boat. Just make it so when you’re not holding down a key it will change some sort of “Moving” bool to false, likewise for when you’re holding it down but change it to true.

With CAS, you can bind a function to a key but I don’t remember if you can check when you let go of it. Inside of the function, you could change the moving bool to true or something.

Let me know if you need any more help!

1 Like

Instead of tweening, use lerping because it’s not straightforward from start to goal and the goal always changes.

1 Like

I was thinking of just changing the walkspeed from 0 to 16 over a span of like 1 second, but if I am correct according to this post that would break the game?

I don’t think this would work, because WASD are keys that you use to move. You would have issue similar to this person:

(i and o are used to zoom your camera in and out, similarly to how WASD are used to move)

You can use UserInputService to detect input and then use a VectorForce inside of the player’s HumanoidRootPart.

Yeah, that is their question. They want to add acceleration to players for when they’re moving.