How to calculate the vector between the mouse cursor and the player?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ProbablyIdiot

So, I’ve been trying to make a top-down maze game where you navigate the maze by using the recoil from shooting a gun. I have watched some youtube videos, and have worked out how I’m going to calculate the movement:

  • Find the vector between the player’s current position and the mouse cursor
  • Multiply the above vector by -1
  • Set the player’s velocity to (0,0)
  • Add the vector to the player’s velocity

Please can someone explain how to do step 1 (in gdscript)? I am relatively new to Godot and only have a partial understanding of vector maths, any help would be appreciated.
Thanks in Advance.

:bust_in_silhouette: Reply From: jgodfrey

To find a vector pointing from A to B use B - A. So, to find the vector pointing from the Player’s position to the mouse position (assuming a script running on the player scene):

var vect = get_global_mouse_position() - position