How can I make LinearVelocity controllable?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to make a LinearVelocity force be controlled by a player pressing buttons, such as a train. I need it to not just be instantly stopping/starting but “warming up” in a sense, so you hold w to go speed up and s to slow down, like a braking system.

  2. What is the issue? I don’t have an issue, I just hoping to find a way to do this.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I have looked around google but I have only found one video on the basics of linear velocity.

My thoughts would be to use UserInputService to detect when W/S is pressed to slowly add/remove the amount of velocity from the object.

What could I do?
Thanks in advance,
pevdn

Have you tried checking every frame or some other time period, and check if W/S is held down? if yes, increment the speed to the appropriate value

You can use a loop to gradually increase it to the MaxForce and break the loop when the player stops holding the key down.

Might as well tween it at that point

I don’t know if it is just me being a newbie at scripting, but I do not know how to check a frame. Do you have a brief overview of it or would it be something worth spending more time on.

Hehe, yeah probably. I wasn’t aware that tweens could be interrupted so I figured it wasn’t possible to vary the speed using W or S as a command.

the video below uses VectorForce to push the players character in a direction that the player can control using WASD or the touchscreen DPAD

it uses drag to make the character reach terminal velocity

you can adjust the amount of force and drag to effect how quickly it reaches terminal velocity

1 Like