system
February 22, 2022, 11:09pm
1
Attention
Topic was automatically imported from the old Question2Answer platform.
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…
system
February 22, 2022, 11:43pm
2
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.
system
February 23, 2022, 12:49am
3
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