Maths Question - move camera based on mouse distance from centre

I have implemented a feature that moves the screen/camera towards the direction the mouse is facing, so that you see more of what is in front of you, I have uploaded a movie showing the affect.

My code is awful though and I would rather not paste it :frowning: I basically check where the mouse is and move the camera until it is X pixels from the center.

What I would like is for the screen to peak forward relevant to how far you move the mouse from the character. I have seen this affect in a few games and wonder if there are any code examples be it Java or Pseudo.

Poor mans version:

IGeyGHRv2nM

Thank you

This gives me the x and y distance from the center of the screen. but keeps on moving away from Character, do I just set a max distance from the Character?


public void position_by_facing(){
  tmp.set(0, 0, 0);
  this.getCam().unproject(tmp);
		
  mouse_offset_x = renderer.getMouse_x() - (Gdx.graphics.getWidth()/2);
  mouse_offset_y = renderer.getMouse_y() - (Gdx.graphics.getHeight()/2);

  renderer.getCam().position.y -= mouse_offset_y * 0.01f;
  renderer.getCam().position.x += mouse_offset_x * 0.01f;
}

y4bZ8R9j2ng

Is the mouse center (0,0)? Or is the topleft corner (0,0)?

Centre of the screen returns 0,0