I want to get the exact position of the enemy even if it rotates.

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

I am now creating an omni-directional shooter
I would like to implement a homing laser to hit the enemy, but due to the player’s rotation, the laser does not fly in the intended direction because it is out of alignment with the original position of the enemy.
I tried to find a method in Vector2 that would give a good result, but it did not work.
Is there any good way or formula to do this?
Or is there a formula for this?
source code

var h = load("res://Graphics/Bom/Horming.tscn")
var h_instance = h.instance()
print(h_instance)
var speed = 1000
var angle = -90 + rand_range(-45, 45)
add_child(h_instance)
while len(enemy_list) > 0:
    var enemy = enemy_list.pop_front()
    print(enemy)
    var enemy_direction = Vector2(cos(self.rotation_degrees), sin(self.rotation_degrees))
    for j in range(0, 32):
        yield(get_tree().create_timer(0.5), "timeout")
        h_instance.start(speed, angle, Vector2.ZERO, enemy.position.rotated())

Edited to fix code formatting…

jgodfrey | 2022-12-17 15:36

:bust_in_silhouette: Reply From: timothybrentwood

I think you just change add_child(h_instance) to get_parent().add_child(h_instance).

Thank you.
I got the results I was hoping for.

eunahya | 2022-12-18 03:20