Is there a better way to do a slash with the mouse?

I have a game where the mouse does various things to attack enemies on screen.

If you are wondering, it’s a 2.5D game. The enemies are in 3D space and the mouse and it’s animations are 2D.

I want a slash animation that goes between the mouse initial click position to the release position.

Since it’s in 2D space, I know their positions in (x, y) and can therefore use trigonometry to set the angle of my animation with tangent (sine and cosine work too) but I need to figure out where the 2nd point is in relation to the 1st.

func _physics_process(delta):
    ...
    if (x1 < x2 and y1 < y2) or (x1 > x2 and y1 > y2):
        ang -= a
    else:
        ang += a
    if y1 < y2:
        ang += 180
    elif y1 == y2:
        if x1 < x2:
            ang += 90
        else:
            ang -= 90
    ...

Then the scale and position are done with more calculations.

Here’s a picture if you’re lost:

px is pixel size of the sprite. So, if Z=30 and px=30 then the scale should be 1, if Z=60 then it should be 2, etc.

The position is centered around the middle and all you have to do is make a smaller triangle to get the mid point or any other point really. This could also be used to check if there are enemies in the slash but only in 2D (there’s probably a better way anyway).

IN THEORY this should work (- some specific scenarios). But, I think there’s probably a better way of doing this that I don’t know about, that’s why I’m asking if anyone has better Ideas or knowledge about this.

Your description of the problem is not clear enough.

I’m no expert, but it might be simpler to use Input.get_axis()for finding the directional quadrant

After a long time, I came up with this:

Main scene:

extends Node

@export var slh: PackedScene

var click2d = Vector2.ZERO
var clickstart = Vector2.ZERO
var clickend = Vector2.ZERO
var timer = 0
var comp

func _input(_event: InputEvent) -> void:
	click2d = get_viewport().get_mouse_position()
	if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
		if timer == 0:
			clickstart = click2d
		clickend = click2d
		timer += 1
#---Check for Taps or Slashes---
	elif timer != 0 and timer <= 10 not Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
		comp = clickend - clickstart
		if comp[0] < 0:
			comp[0] -= comp[0]*2
		if comp[1] < 0:
			comp[1] -= comp[1]*2
#---If it's a Tap, the below statement should be true.
		if comp[0] + comp[1] <= 10:
			pass
#---Otherwise it calculates for Slashes.
		else:
			var scale = sqrt(comp[0]*comp[0] + comp[1]*comp[1])
			var slash = slh.instantiate()
			comp = clickend - clickstart
			var rot = 0
#Change the 0 and 1 in case your texture is facing left or right.
			var angle = atan(comp[0]/comp[1])
			rot -= angle
#This is for turning the texture past 180°. Change it if your texture doesn't face down.
			if comp[1] < 0:
				rot += deg_to_rad(180)
#The 64 is the size of my Slash texture NOT the size of the Texture Image (68).
			slash.initialize(scale/64,rot,clickstart,clickend)
			add_child(slash)
			timer = 0
	else:
		timer = 0

Slash scene:

extends Node

var position
var clickstart
var clickend
var scale
var frames = 0

func initialize(s, rot, cs, ce) -> void:
	$AnimationPlayer.play("ON")
	$Sprite2D.rotation = rot
	clickstart = cs
	clickend = ce
	scale = s

#---This is to get it's position (You can put it in the "initialize" function if you want)---
func _process(_delta: float) -> void:
	position = ((clickend - clickstart) / 2) + clickstart
#This is optional. I made it because the animation shrinked to the middle of the texture.
	if frames > 0 and frames < 5:
		position = ((clickend - clickstart) / 10 * 5.5) + clickstart
		if frames == 1:
			scale = scale / 10 * 9
	elif frames > 4 and frames < 9:
		position = ((clickend - clickstart) / 10 * 7) + clickstart
		if frames == 5:
			scale = scale / 9 * 8
	elif frames > 8 and frames < 12:
		position = ((clickend - clickstart) / 10 * 8.5) + clickstart
		if frames == 9:
			scale = scale / 8 * 5
	elif frames > 11 and frames < 14:
		position = ((clickend - clickstart) / 10 * 9) + clickstart
		if frames == 12:
			scale = scale / 5 * 4
	elif frames > 13 and frames < 17:
		position = ((clickend - clickstart) / 10 * 9.75) + clickstart
		if frames == 14:
			scale = scale / 4 * 2
#---This part is needed.
	$Sprite2D.global_position = position
	$Sprite2D.global_scale.y = scale
#Not this.
	frames += 1

#---This is to erase it once it's over---
func _on_timer_timeout() -> void:
	queue_free()

This is the best I came up with.
It took me a while but I hope this helps someone at some point.