Issues with monogame camera

Hello,

So I’m making a game similar to Stardew Valley, I’ve implemented a camera that moves all the surroundings while the player remains fixed. I’m trying to make it so that the player can select objects around them but the further away I move from 0,0 Camera position the more inaccurate the select cursor becomes more off from the player position:

The code for the camera position and hit location:

Vector2 camera_pos = Vector2.Transform(Game1.camera_pos, Matrix.Invert(Matrix.CreateScale(Game1.scale_x, Game1.scale_y, 1.0f)));
if (Keyboard.GetState().IsKeyDown(Keys.D))
{
direction = ‘D’;
hitlocation = new Vector2((player_rect.X / 16) * 16 + 16, ((player_rect.Y / 16) * 16) + 16);
hitlocation.Y -= ((int)(camera_pos.Y / 16) * 16);
hitlocation.X -= ((int)(camera_pos.X / 16) * 16);
if (Collision.predict_collision_map(player_collision_rect, 2, 0) == false)
{
Game1.camera_pos.X -= player_walking_speed;
}
}

Fixed Matrix:

scale_x = (float)(graphics.PreferredBackBufferWidth1.25) / 800;
scale_y = (float)(graphics.PreferredBackBufferHeight
1.25) / 480;
fixed_matrix = Matrix.CreateScale(scale_x, scale_y, 1.0f);

Drawing the player:

spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: fixed_matrix);
player1.tick();
spriteBatch.End();

Drawing the hit location(green square):

matrix = Matrix.CreateScale(scale_x, scale_y, 1.0f) * Matrix.CreateTranslation(newVector3(camera_pos.X, camera_pos.Y, 0));
spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: matrix);
player1.tick_hit();
spriteBatch.End();

Original Position (0,0):
image

As I move to the right:
image

You likely have to convert your screen coordinates (ie, where your mouse clicks on the window) to world coordinates (ie, where things are in the game). I notice you have some scale in there as you build a matrix to submit to the sprite batch. From what you’re describing, that’s likely the culprit. You’ll need to apply that same scale to your mouse position to bring it into your world.

It isn’t using the mouse at all the hit location just needs to be in whatever the direction the player is facing

Fair enough, but I’d still check how you’re applying the scale. You’re saying that the position gets more and more inaccurate the further you move away from the origin, which is usually a pretty strong indicator.

Actually, do you even need to apply scale at all since everything would already be in world units?

Something else that occurs to me to ask… do you know if your hit detection is working properly and it’s the rendering that’s off, or is the actual hit detection wrong too?