Godot Version
4.4.1
Question
Hi guys, I’m creating a ball, that has guns attached on it.
It’s a component system. The Grow Value is the base value, Grow Plus add 1 to Grow Value. MarkerManager will add a number of marker2D based on Grow Value, then GunManager attach Gun scene to it.
So far, MarkerManager and GunManager work well, they both add Marker2D and Gun to the scene, at least it printed out in Output.
But the actual guns are not appear in game. I can’t find it, I tried to scale it up, add a ray collision to find it easier, but it still missing. I don’t know where I got wrong.
The ball
The gun
Here is my code in Marker and Gun Manager:
func setup_marker():
if body.has_node("GrowValue"):
var marker_amount = body.get_node("GrowValue").value
if body is Ball:
var ball_radius = body.get_node("CollisionShape2D").shape.radius
var angle_step = TAU / marker_amount
for i in range(marker_amount):
var marker = Marker2D.new()
body.add_child(marker)
var angle = i * angle_step
marker.position = Vector2(cos(angle), sin(angle)) * ball_radius
marker.rotation = angle
marker_list.append(marker)
print("Marker position: ",marker.position)
print("Marker list: ", marker_list)
func setup_gun():
if body.has_node("GrowValue") and body.has_node("MarkerManager"):
var marker_list = body.get_node("MarkerManager").marker_list
if body is Ball:
for marker in marker_list:
var gun = Gun.new()
body.add_child(gun)
gun.position = marker.position
gun.rotation = marker.rotation
gun.scale *= 2
gun_list.append(gun)
print("Gun position: ", gun.position)
print("Gun list: ", gun_list)
Thank you for your time!