0 votes

Hi!
What I want to achieve is something like this:
As you can see, the middle is aiming to the player
Currently, it doesn't aims to the player well, and I don't know how to fix that. It always aims off.
Thecnical stuff: (My code is at the bottom)
I'm rotating a vector2 (radius) and spawn the bullets at it's position. I'm making a regular node (center) lookat() the player, and add it's rotation to the vector2 (radius)
(The player and the enemy are KinematicBody2D-s and the bullets are Area2D-s wich have their globalposition updated.)
I'm using a lot of ideas from this queastion'S 2nd aswer:
https://godotengine.org/qa/12826/spawning-objects-around-a-circle

This is how it aims: (The flame thingy shows the rotation of the center,
but as you can see, the bullets are not spawned at a correct position)
enter image description here

(If you need any more information, just say it, because I don't know what else to say.)
BTW the visuals will be worked on after I will fix the main BUGs in the game. (just like this one)

export(int) var shoot_angle = 90  # in degrees
export(int) var numb_of_bullets = 3
export(float) var time_between_shots = 0.5
var radius = Vector2(100, 0)
onready var center = get_node("Center")
var angle_step = shoot_angle / numb_of_bullets

center.look_at(player_node.global_position)

for i in range(numb_of_bullets):
  var spawn_pos = center.global_position + radius.rotated((center.global_rotation / 2) + angle_step * i) # * sign(center.global_rotation / 2))

var node = bullet.instance()
node.global_position = spawn_pos
get_parent().add_child(node)
node.move_direction = global_position.direction_to(node.global_position)
asked Jun 30 in Engine by Czselu349 (139 points)

Please log in or register to answer this question.

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 How to use this Q&A? before posting your first questions.