4.3 - Restrict Mouse from within 20 px of the Character

To use warp_mouse you have to convert global/canvas coordinates to screen coordinates. Here is an answer that has links on how to do that: Input.warp_mouse doesn't work as intended after resizing game window - #2 by Sauermann

An alternative/easier approach would be to just get the distance from the ship to the cursor and only rotate to the mouse position when the distance is big enough.
Something like this:

var mouse_pos := get_global_mouse_position()

if global_position.distance_to(mouse_pos) > 20:
  look_at(mouse_pos)

This doesn’t stop the mouse but it does stop the ship from reacting.

1 Like