Runless script Problem

I have a problem.
When I press A or D the player moves to the right or to the left instantly.
But I would like this to happen more slowly and smoothly.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMotor : MonoBehaviour {

    private CharacterController controller;
    private Vector3 moveVector;

    public float smooth = 2;
   

    private float speed = 5.0f;

    private float verticalVelocity = 0.0f;
    private float gravity = 12.0f;
    private float jumpForce = 5.0f;

    // Use this for initialization
    void Start () {
        controller = GetComponent<CharacterController>();
       
    }
   
    // Update is called once per frame
    void Update () {
        moveVector = Vector3.zero;

        if (controller.isGrounded)
        {
            verticalVelocity = -0.5f;
            verticalVelocity = -gravity * Time.deltaTime;
            if (Input.GetKeyDown (KeyCode.Space)) {
                verticalVelocity = jumpForce;
            }
        }
        else
        {
            verticalVelocity -= gravity* Time.deltaTime;
        }
        //X
        if (Input.GetKeyDown(KeyCode.A))
        {
           
            Vector3 newPosition = controller.transform.position;
            newPosition.x--;
            controller.transform.position = newPosition;
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
           
            Vector3 newPosition = controller.transform.position;
            newPosition.x++;
            controller.transform.position = newPosition;
        }
        //Y
        moveVector.y = verticalVelocity;
        //Z
        moveVector.z = speed;

        controller.Move(moveVector * Time.deltaTime);




    }
}

you can change the Input settings of your project.
Another way would be to add a Rigidbody and use Rigidbody.addforce instead of CharacterController.move

I meant lateral movement

GetKeyDown will only ‘trigger’ when the key goes down, so you probably want to use ‘GetKey’ , instead for gradual movement. From your example code, I’d say that you want to make ‘moveVector.x’ equal to the new x position. Then, when it’s multiplied by Time.deltaTime in your call to ‘controller.Move’ it should do what you want.

This response was shortened from a longer explanation of options, because I believe this is more suitable :slight_smile: