GameObject Jumping when I try to drag it

I have a code that allows me to raycast to an object and then drag it around the screen, my problem is that whenever I click on the object it jumps around the screen before I can drag it. I’m not sure what the problem could be, here’s my code.

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

public class CreatureMaster : MonoBehaviour
{
    public Camera MainCamera;
    private UIMaster UI;

    public GameObject Selected;

    public float MoveSpeed = 1000;

    private Vector2 Mouse1;
    private Vector2 Mouse2;
    private Vector2 MoveDirection;
    void Start()
    {
        UI = this.gameObject.GetComponent<UIMaster>();
    }
    void Update()
    {
        if (UI.ScreenLocked && Input.GetMouseButtonDown(0))
        {
            Vector3 MousePosition = Input.mousePosition;
            Ray ray = MainCamera.ScreenPointToRay(MousePosition);
            RaycastHit hit;
            if(Physics.Raycast(ray, out hit, 20))
            {
                if (hit.transform.gameObject.tag == "Creature")
                {
                    Selected = hit.transform.gameObject;
                }
                else { Selected = null; }
            }
        }
        if (UI.ScreenLocked && Selected != null && Input.GetMouseButton(0))
        {
            Mouse1 = Mouse2;
            Mouse2 = Input.mousePosition;
            MoveDirection = (Mouse1 - Mouse2) * -MoveSpeed * Time.deltaTime;
            Selected.transform.Translate(MoveDirection.x, 0, MoveDirection.y);
        }
    }
}

The problem in your case is that you use screen coordinates (mouse position) to move object in 3d world (Translate method), this is different values.

What you can do with current code is normalize value, you only need direction of movement, then play around with MoveSpeed (you’ll need smaller value than 1000, around 20 or so):

MoveDirection = (Mouse1 - Mouse2).normalize * -MoveSpeed * Time.deltaTime;

But, if you want object to follow the mouse more precisely, you will need to use another approach. Briefly speaking, you’ll need to get mouse position (screen units) and convert it to the world position, then apply world position to your object every frame.

Something like this if I understand your scene setup correctly:

if (UI.ScreenLocked && Selected != null && Input.GetMouseButton(0))
{
    Vector3 screenPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, MainCamera.transform.position.y);
    Vector3 worldPos = MainCamera.ScreenToWorldPoint(screenPos);

    Selected.transform.position = worldPos;
}