GameMaker Getting instance position on screen

I am trying to draw a line from
the player to the mouse. Since I am using matrix projections I can't use mouse_x or mouse_y to calculate this. The player isn't always centered on the screen so I need to find its position on the screen. Right now the code is :

guix = (obj_player1.x - x+global.default_camera_w/2) / global.default_camera_w * display_get_gui_width() + view_xport[0];
guiy = (obj_player1.y - y+global.default_camera_h/2) / global.default_camera_h * display_get_gui_height() + view_yport[0];

draw_line(guix,guiy,window_mouse_get_x(), window_mouse_get_y());

However, there is a slight mismatch that grows bigger the further the player moves from the center of the camera.

Any help would be greatly appreciated :)
 
Top