How to use the cursor position to apply even velocity

Godot Version

Godot 4.3

Question

I am trying to apply recoil in my top down 2d game. To apply recoil in the opposite direction, I am just setting my velocity to the negative of the cursor position.

	var target_pos = get_global_mouse_position() - position
	velocity = -target_pos
	move_and_slide()
#Inside fire function

But this creates a problem because depending on how far my cursor is from the player, the recoil will vary. Please help!

Normalize the vector and then scale it by how much velocity you want:

const RECOIL_VELOCITY: float = 100.0 # or whatever

[...]

    var target_pos = (get_global_mouse_position() - position).normalized()
    velocity = -target_pos * RECOIL_VELOCITY
    move_and_slide()

Normalizing makes the vector be length 1.0, however long it was before.

edit: syntax errors

Ok, thank you!