0 votes

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.

Godot version 3.5.stable.official (steam version)
in Engine by (12 points)

1 Answer

0 votes

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
by (16,852 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.