How do I turn a float value into movement?

Ok, so I’ve been trying to make a top-down game that involves a hard to control drone with heavy acceleration. I found a useful tutorial on how to create a float that rises in value or lowers in volume, depending on which key you press. That’s all well, but now I want my character to move like that as well. Here’s my code:

    public float value;
    public float timeFromZeroToMax = 2;  // How long it takes to reach max

    private void Update()
        float MoveTowards = 0;

        float changeRatePerSecond = 1 / timeFromZeroToMax * Time.deltaTime;

        if (Input.GetKey(KeyCode.J))
            MoveTowards = -1.0f;
        if (Input.GetKey(KeyCode.L))
            MoveTowards = 1.0f;

        value = Mathf.MoveTowards(value, MoveTowards, changeRatePerSecond);


I saw other articles about acceleration, but they were all too complicated for me. And if the only way I can do this is complicated, that’s fine too. Thanks.

If ‘J’ and ‘L’ represent left and right, then you could make a very basic movement system like this:

void Update()
     // Your code

     transform.position += transform.right * MoveTowards * MovementSpeed * Time.deltaTime;

Hopefully, this will allow the player to move infinitely in a direction. @DillyFish

Hello @DillyFish !

There are two ways to do this: using a rigidbody or translating, but in this case, I think you should go with rigidbodies.

When you do Physics stuff, the optimal place to do it is inside FixedUpdate, because it runs on a fixed rate.

A good way is to give force to the object in this scenario:

private Rigidbody droneRigidbody; //This way you can add this from the editor.
private void FixedUpdate()
    if(droneRigidbody.velocity < TheMaxValueYouPutInHere) //a condition against too much  speed.
    	droneRigidbody.AddForce(yourSpeedValue, ForceMode.Acceleration); //if your speed value is 
        0, it basically won't give it any force.

I hope that this was helpful, or just gave you a direction, if anything is wrong about my answer, please correct me. :slight_smile: