0 votes

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())
in Engine by (15 points)
edited by

Edited to fix code formatting...

1 Answer

+1 vote
Best answer

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

by (3,900 points)
selected by

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

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.