How would I get a fireball to follow mouse position when clicked?

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

I have the basic code set up when tab is pressed the fireball is shot from the sprite, but I want to know how when tab is pressed the fireball shoots in the direction the mouse is

if anyone knows, pls help

thanks

:bust_in_silhouette: Reply From: kidscancode

Get the mouse position with CanvasItem.get_global_mouse_position():

var mouse_position = get_global_mouse_position()

Then you can get a direction vector with:

var direction = (mouse_position - position).normalized()

Without knowing how the rest of your code is set up, that should be enough get you started. I highly recommend reading this: