How to make Enemy throw projectile at Player direction ?

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

I can make the projectile spawn’s but it just stay’s there, and i can make it go to some direction’s but not where the player is moving…

Is a top down 2D game…

:bust_in_silhouette: Reply From: jgodfrey

It somewhat depends on how you’re handling motion in your game. I’d guess the accepted answer here should be useful to you. If that’s not enough to get you going, I’d suggest you post (and properly format for the forum) the relevant code from your projectile and enemy scripts for additional assistance.

:bust_in_silhouette: Reply From: codelyok13

If you are hand-designing your physics, you can use Vector2’s move_towards to move the object in the direction of the player as they move.

var new_prjk_pos = cur_prjk_pos.move_towards(player.position, "some int value closer");

Link to Godot Article for method

If you are using sometype of Physics engine,

var direction_toward_player = project_pos.angle_to(player_pos)
var new_acceleration_of_projectile = projectile_acceleration.rotated(direction_toward_player)
projectile_acceleration = new_acceleration_of_projectile 

Vector2 Angle_To
Vector2 Rotated