[CODE]Keep Gameobject position exactly at mouse cursor when cast float position to int

Hey everyone! I’m creating a 2d top-down game and currently im working on a script which should keep
the Gameobject position exactly at the same position of the mouse, but it doesn’t work.
Maybe it’s because I’m casting a float to an int, but I have seen other games where it works very well.

Problem:
When I move the mouse very fast the object glitches from it’s position

I hope anyone can help me!

void Update ()
    {
        mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        yMin = (int)playerRectAncor.transform.position.y - 1;
        yMax = (int)playerRectAncor.transform.position.y + 1;
        xMin = (int)playerRectAncor.transform.position.x - 1;
        xMax = (int)playerRectAncor.transform.position.x + 1;

        if (true) //Its just temporary true, for testing
        {
            pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            pos.z = transform.position.z;
            pos.x = Mathf.Clamp(pos.x, xMin, xMax);
            pos.y = Mathf.Clamp(pos.y, yMin, yMax);
           // put Object position to mousePosition
            rectObj.transform.position = new Vector3((int)pos.x, (int)pos.y, (int)pos.z);
        }

Hey, thank you for your answer, it’s difficult for me to describe my problem in english, maybe I described it bad, the point is that the game is tiled-base, and I’m casting it to an int because the whiteRect should only move in integers so the player can only build in a certain range around him.

In a nutshell, player should only be able to move the whiteRect in a 3x3 Range around his character otherwise he would be able to dig a hole out of his range^^
And moving the rect without casting it to an int seems not suitable to the kind of game im trying to create.

Here is a picture, it’s like building in Stardew Valley:

@Bunny83
@RocketFriday
@Orokon