0 votes

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!

Godot version v3.5.1.stable
in Engine by (12 points)

1 Answer

0 votes

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 =movetoward(movement.x, mousepos.x, delta)
movement.y=movetoward(movement.y, mousepos.y, delta)

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

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

by (195 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.