why is my cube moving sideways in inconsistent distances?

I’m trying to make a cube move by 1 or -1 on the x axis when pressing “a” or “d” (and also making the cube move forwards, but that seems to be working). this is what i currently have.

public Rigidbody rb;
    public float fforce = 2000f;
    public Vector3 side = new Vector3(1, 0, 0);
    public Transform pc;
    // Update is called once per frame
    void FixedUpdate()
        rb.AddForce(0, 0, fforce * Time.deltaTime);

        if (Input.GetKeyDown(KeyCode.A))
            transform.position = pc.position - side;
        if (Input.GetKeyDown(KeyCode.D))
            transform.position = pc.position + side;

for example, when i press “d” sometimes the cube moves by 1 but sometimes by 2 or 3. I’m very new to unity so maybe this is a stupid question, but i really don’t know whats the problem here and i’d appriciate any help.

My assumption is that it’s because you are calling it from FixedUpdate, while Input’s state gets updated in Update. Update is called once per frame, FixedUpdate is called a fixed amount of times per second. There can be multiple FixedUpdates per Update, there can be multiple Updates per FixedUpdate.
It says in the documentation for GetKeyDown:

You need to call this function from the Update

So I’d try that.
If you really have to apply the state change (the transform.position change) in the FixedUpdate, then read the Input in update, save it in some variable and read it from Fixedupdate

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

public class PlayerController : MonoBehaviour
    //This script will control our player movement in our game

    public float moveSpeed;
    public float jumpForce;

    private Rigidbody rig;

    private void Awake()
        //get the rigidbody component
        rig = GetComponent<Rigidbody>();

    void Update()


    void Move()
        //getting our player control inputs
        float xInput = Input.GetAxis("Horizontal"); //will return an X value of -1 to 1. If no button is pressed then value will be 0
        float zInput = Input.GetAxis("Vertical");//will return a Y value of -1 to 1. If no button is pressed then value will be 0

        Vector3 dir = new Vector3(xInput, 0, zInput) * moveSpeed;
        dir.y = rig.velocity.y; //setting y to whatever existing velocity is

        rig.velocity = dir; //applying our Vector3 to our rigidbody
        //note: the 'velocity' is a Rigid3 itself as well ^

        Vector3 facingDir = new Vector3(xInput, 0, zInput); // 'magnitude' is this vector's length

        if(facingDir.magnitude > 0) //if magnitude is NOT zero, then we change the facing direction forward with this code
            transform.forward = facingDir;

    void TryJump()

        Ray ray = new Ray(transform.position, Vector3.down); //we are shooting the raycast in a downward position to check if we are on the floor

        if(Physics.Raycast(ray, 0.7f)) // first value 'ray' is the direction we're shooting in, 0.7f is how faf we are shooting the raycast
            rig.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);