Area2d doesnt move with with .move_toward()

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

So i want a projectile(Fireball) to shoot in mouse direction, so i have a function in my Player script that makes a instance of the Fireball per click, and that works perfect,

func Fireball():
	var Fireball = load("res://Magic/Fireball/Fireball.tscn")
	var fireball = Fireball.instance()
	var Level = get_tree().current_scene
	Level.add_child(fireball)
	fireball.position = get_global_position()

But the script for shooting the Fireball in mousedirection doesnt work, The Projectile does not move

extends Area2D

var speed = 10
var movement = Vector2()
onready var mouse_pos = null

func _ready():
	mouse_pos = get_global_mouse_position()
	
func _physics_prozess(delta):
	
	movement = movement.move_toward(mouse_pos, delta)
	movement = movement.normalized() * speed
	position = position + movement

I cant figure out what im doing wrong, thank for your anwers!

:bust_in_silhouette: Reply From: CassanovaWong

move_toward only works with floats, i think

so you need two lines, one for x and one for y… and the movement

movement.x =move_toward(movement.x, mouse_pos.x, delta)
movement.y=move_toward(movement.y, mouse_pos.y, delta)

or you could make one long lkine… and I’d add a speed , I think, or else its too slow?

movement = Vector2(move_toward(movement.x, mouse_pos.x, delta*speed), move_toward(movement.y, mouse_pos.y, delta * speed) )